Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mix mode input of a binary open file Question!
#5
(11-28-2024, 02:02 PM)Petr Wrote: Nice work, Steve. It depends on the programmer's approach, I realized. While you are providing a way to do it, I was looking for reasons not to do it Smile

It will work via binary access as you write here, but it won't work via Input and a file opened for reading, because some characters control the behavior of the input command in Open for Input mode.

The following program shows how binary text can confuse the Input command when reading a binary file.

Code: (Select All)

For a = 0 To 255
    f$ = Chr$(a) + f$
Next a

ff = FreeFile
Open "binTest" For Binary As ff
Put ff, , f$
Close ff

ff = FreeFile
_ControlChr Off 'not for operations in file, just for printing...
Open "binTest" For Input As ff
Dim b As String
Do Until EOF(ff)
    Input #ff, b$ 'or try LINE INPUT, returned string is not returned in full lenght
    Sleep
    Print b$, Len(b$)
Loop
Close ff

It's not supposed to.  If you need to read a full binary range of characters (from 0 to 255 ASCII), you can't use INPUT.  There are various old-school control codes embedded into INPUT, which are necessary for us to honor so that old QB45 programs can still compile and run the same as always with files written using those rules.

CHR$(26) is one of those terminal characters, if I remember correctly (it's CTRL-Z) and if basically counts much the same as an EOF marker.  With it you used to be able to write a data file like so:

Red Bus, 1, 2, 3, 4, CHR$(26), Blue Bus, 1, 2, 3, 4, CHR$(26)....

Now, you could OPEN that file and read to EOF, and you'd only read to the CHR$(26) character.  INPUT would basically return
Red Bus
1
2
3
4

IF you wanted the second file of data, you would SEEK #1, proper_position and then do the INPUT so you get
Blue Bus
1
2
3
4
(CHR$(26) as EOF marker)

Think of it as an old-school way of packing multiple text files together into one single file.  You had your own individual data streams, all separated by that control character.

Reading a file as BINARY, you don't have those control characters.  You'd have to account for them yourself, if you program made use of them or not...

But they're the reason why you're seeing breaks when using INPUT to read a BINARY file.   INPUT was never made to read the whole 256 ASCII character range.  It was made more for text input, with control characters embedded into the stream to help organize it into better and more manageable data.  Wink
Reply


Messages In This Thread
RE: Mix mode input of a binary open file Question! - by SMcNeill - 11-28-2024, 02:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  a question about OpenGL in QB64pe: TempodiBasic 11 1,834 11-22-2025, 05:47 PM
Last Post: TempodiBasic
  How do you boot Win 11 in Safe Mode? Pete 8 5,868 10-30-2025, 06:03 AM
Last Post: SMcNeill
  Download the file from the internet and extract the .zip file quickbasic 6 670 10-25-2025, 01:39 AM
Last Post: madscijr
  Question about load pictures Jim_001 4 529 10-22-2025, 06:19 AM
Last Post: Unseen Machine
  Test to post a new Thread + question 32 or 64 bit Rudy M 2 546 09-09-2025, 04:10 PM
Last Post: Rudy M

Forum Jump:


Users browsing this thread: 1 Guest(s)