How do you simulate byte arrays in Qbasic. Since getting QB7 from Chimpface9000 I've been interested again but using "open file for binary as #1" do you "Get" to a string do you?
and use string manipulation...
Is this right?
Printable View
How do you simulate byte arrays in Qbasic. Since getting QB7 from Chimpface9000 I've been interested again but using "open file for binary as #1" do you "Get" to a string do you?
and use string manipulation...
Is this right?
Yo Paul; You can just use this:
Then you can use the REDIM statement to size it later on.Code:DIM btArr() AS STRING * 1
I prefer to just use a string and read the whole file into the string at once, rather that one byte at a time. It is faster to read the whole file (or a large chunk):
NOTICE: You get an error if the file is longer than approx. 32K because that is the max a string can hold.Code:FUNCTION ReadFile$(FileName$)
DIM fileNum AS INTEGER
DIM fileLen AS INTEGER
DIM fileBuf AS STRING
fileNum = FREEFILE
OPEN FileName$ FOR BINARY AS #fileNum
fileLen = LOF(fileNum)
fileBuf = SPACE$(fileLen)
GET #fileNum, , fileBuf
CLOSE fileNum
ReadFile$ = fileBuf
END FUNCTION
Thanks
An actual bytearray (like in C++) can hold infinite(or however big your memory is) because it's more so an Array, or linked list so to speak. which has each element pointing to the next. just thought you'd be curious to know because in any case a byte is only 8bits ( I forget whats the smallest type that can hold an 8bit ) least that way if you use possble a 'Byte' type, you can create an array of them, and then redim them, I think it has a higher limit than the String approach. you'd need to convert the file's text into a byte tho using that Asc$