PDA

Click to See Complete Forum and Search --> : Byte arrays


Paul282
May 21st, 2000, 12:16 PM
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?

HaxSoft
Jul 19th, 2000, 04:28 PM
Yo Paul; You can just use this:

DIM btArr() AS STRING * 1

Then you can use the REDIM statement to size it later on.

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):


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


NOTICE: You get an error if the file is longer than approx. 32K because that is the max a string can hold.

Paul282
Jul 19th, 2000, 08:52 PM
Thanks

kb244
Jul 20th, 2000, 07:53 AM
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$