Results 1 to 4 of 4

Thread: Byte arrays

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Question

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

  2. #2
    Fanatic Member HaxSoft's Avatar
    Join Date
    May 2000
    Location
    Ohio
    Posts
    593

    Talking

    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Thanks

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  4. #4
    Addicted Member
    Join Date
    May 2000
    Location
    Grand Rapids, MI
    Posts
    231
    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$
    -Karl Blessing aka kb244{fastHACK}
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width