Post

 Resources 

Console


Actually MetalWarrior (1 reply, 0 views) (2000-Oct-20)
-
Actually, even tho you seem to have found a solution, let me quick explain why you had the problem, and a better definition of the solution. In Binary mode, when you write a variable to a file, it writes the exact bytes. It doesn't write any information on the length of a variable. When you read a variable, it reads the exact amount of bytes needed for that variable. So, when working with most variables, this is no problem. A long is always 4 bytes, reading or writing it. An integer is always 2, a byte always 1, and so forth. However, a String can be any length. So if you write a string equal to "test", and then read a String defined as readStr * 12, you read an extra 8 characters that you don't need, and more importantly, could belong to another set of information. So, there are two good ways to do Strings in Binary mode. One, is to keep your Strings the same length in both reading and writing. In other words, Dim your Strings as "suchandsuch * 10" or whatever your variable name and length are going to be. The other way is to manually store the string length ahead of the string itself. So, you would first write a Byte or Integer, which was equal to Len(YourString), and then write YourString. Then, when reading, you would load the length variable first, set ReadString = Space(StrLen), which fills the reading string with correct amount of spaces, so that it will be the correct length, and then read ReadString. Hopefully that wasn't too confusing. :) Just hope you understand it a bit better now --MetalWarrior


-
Up One Level | Back to Forum

RE: Actually Martin (0 replies) (2000-Oct-20)

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.
There have been 75 visitors within the last 20 minutes
RSS News Feed