Results 1 to 6 of 6

Thread: File Reading

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    I want to read a file and
    put it in a byte array.
    Why wont it put it in the
    array?

    Code:
     
    Dim StrFile as String
    Dim bytTemp() As Byte
    StrFile = "C:\readme.txt" 
        Open strFile For Binary As #1
        Get #1, , bytTemp
        Close #1
    ReadMe.txt:
    Code:
     
    MainBoard : M599LMR
    BIOS Date : Release 03/08/2000S
    
    VGA : SiS Multimedia V1.08
    Sound : Version 2.32
    Modem : Pctel R7.64-pcc-06
    Lan DAVICOM : Version 1.12
    Gamut : Version 1.56
    Super Voice : Version 2.2
    Audio Rack : Version 2.32


    [Edited by Evan on 08-29-2000 at 03:13 PM]

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Private Sub Command1_Click()
    
    Dim StrFile As String
    Dim bytTemp() As Byte
    Dim i As Integer
    
    StrFile = "C:\readme.txt"
        Open StrFile For Binary As #1
     Do Until EOF(1)
     ReDim Preserve bytTemp(i)
        Get #1, , bytTemp(i)
         i = i + 1
      Loop
        Close #1
        
    'for display only List1
    For i = 0 To i - 1
    List1.AddItem bytTemp(i)
    Next
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    No offence HeSaidJoe, but that is the slowest possible way to read a file in, you also seem to be redimensioning the array as a variant, or does a dynamic array stay as the type it was originally declared as? Thats a good question.

    Code:
    Private Sub Command1_Click()
    
    Dim StrFile As String
    Dim bytTemp() As Byte
    
    StrFile = "C:\readme.txt"
    Open StrFile For Binary As #1
    'redim the array to the size of the file
    ReDim bytTemp(LOF(1) - 1) As Byte
    'read the whole file in one go
    Get #1, , bytTemp
    'close the file
    Close #1
        
    End Sub
    [Edited by Iain17 on 08-29-2000 at 05:02 PM]
    Iain, thats with an i by the way!

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    ??

    Ok..

    That works .. all acept the
    file im reading is going to
    be about 100mbs sometimes.
    How do I store it in a byte
    varable with out it over flowing?

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    No offence taken..I only adjusted what was given to make it work.

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Are you sure that is a good idea. 100mb file in memory. Can you not work with chunks of the file? That i think would be better idea. I just tried the code i gave you, and it loaded a 100mb file ok, took some time though.

    Mind you i am running windows 2000, so it may not work on 98.


    Iain, thats with an i by the way!

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