|
-
May 21st, 2000, 11:16 AM
#1
Thread Starter
Fanatic Member
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?
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jul 19th, 2000, 03:28 PM
#2
Fanatic Member
Yo Paul; You can just use this:
Code:
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):
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
NOTICE: You get an error if the file is longer than approx. 32K because that is the max a string can hold.
-
Jul 19th, 2000, 07:52 PM
#3
Thread Starter
Fanatic Member
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jul 20th, 2000, 06:53 AM
#4
Addicted Member
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$
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|