How do I grab 8 bytes as the file name?
...
CartNum = String(0, 8) '''RETURNS NOTHING
Get InputFileIndex, 56, CartNum
First off, you're absolutely right. String(0, 8) DOES return nothing. Or rather, it returns nothing VISIBLE. In reality, CartNum becomes an 8-byte string filled with zeroes. If you were to look at the string in a hex editor, it would show "0000000000000000" - eight bytes of zeroes. The thing is, Chr(0) (the character whose ASCII code is 0) is completely invisible - it shows up as nothing. So what you end up with is 8 bytes of nothing. You could just as easily use 32 (space) or 65 (A) instead of 0; I personally prefer to use 0. However, the fact that it is 8 bytes long is what is important for the next step:
"Get", when used on a file opened For Binary, will return a number of bytes equal to the length of the string used as its third argument. What this means is that if CartNum is 8 bytes when Get is called, Get will put 8 bytes from the file into CartNum. If CartNum was 0 bytes long (the default Null value which all VB strings are initialized to), Get would return 0 bytes instead. So in the end, getting 8 bytes from a file requires setting up an 8-byte-long string (via String(0, 8) in this case), and then calling Get on a file opened For Binary. (A three step process!)
How do I check for four bytes in a row?
...
'LastFour = String(Chr(0), 4) ''DOES NOT WORK
Do While Not EOF(InputFileIndex)
JustOne = Chr(0)
Get InputFileIndex, , JustOne
LastFour = Mid(LastFour, 2) & JustOne
If LastFour = Chr(&H49) & Chr(&H49) & Chr(&H2A) & Chr(&H0) Then
...
Here you caught a mistake I made. I was thinking that String() expected a string value as its first argument, when in reality it wants a number! The line should read
LastFour = String(0, 4) . At any rate, things continue normally from there. We start a loop that will continue until we run out of data. Then we (re)set JustOne to an empty string one byte long, so that the Get line below it will pull out exactly one byte. Once Get does its thing (we left out the second argument to tell Get to continue where it left off), JustOne has the next byte in the file. The next step is to drop the first byte of LastFour (making it three bytes long) while simultaneously adding JustOne to the end (bringing it back up to four bytes). If we don't set LastFour to a 4-byte-long string (using the corrected version of the
LastFour = ... line), the program will still try to drop the first byte from LastFour each time through, but since there isn't anything there for it to drop, the ultimate result will be that LastFour is only a single byte long - which is misleading and distinctly unhelpful.
As far as actually checking four bytes in a row, if LastFour is initialized correctly, the next line will check four bytes from the file for you. The &H inside each Chr() tells VB to read the numbers as hex values instead of decimal, so the If...Then will check for the four-byte sequence that separates each page. After that, things continue onward, splitting the old file into the new format.
Hopefully that helps, although I sense it's a bit late. ^_^;;
- Sen