Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder bobleny's Avatar
    Join Date
    May 2007
    Posts
    256
    Thanks
    3
    Thanked 11 Times in 11 Posts

    VB: Opening a binary file?

    Hey, I have another question!

    I have a binary file with a .rnd extension. I need to read the records. In QBASIC, it could be done like so:
    Code:
    OPEN fileLocation$ FOR BINARY AS #1
        GET #1, recordNumber%, aDataStructure
    CLOSE 1
    From what I can tell, in VB this is how you would open a file:
    Code:
    Dim fileStream As New IO.FileStream(fileLocation, IO.FileMode.Open, IO.FileAccess.ReadWrite, IO.FileShare.None)
    
            Dim file As New IO.StreamReader(fileStream)
    
            Dim records As String = file.ReadToEnd()
    
            fileStream.Close()
    Though this opens the file, I can only seem to read the first line... Maybe it's just me, but this seems to also be a bit more complicated than in QBASIC.

    When I look up how to open a binary file in VB online, everyone says the same thing,
    Code:
    OPEN fileLocation$ FOR BINARY AS #1
        GET #1, recordNumber%, aDataStructure
    CLOSE 1
    However, when I type that in, "Open" just doesn't exist...

    Is anyone able to help me out? I don't understand.

    Thanks!
    --www.firemelt.net--
    * No good deed goes unpunished.
    * Cheer up, the worst has yet to come...
    Get Firefox!

  • #2
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It sounds like you're using VB.NET?
    What you're getting from searching is VB, the two are different languages.

    Code:
    Dim fileToOpen as New FileStream("file.txt",FileMode.Open,FileAccess.Read)
    Dim fileToRead as new StreamReader(FileToOpen)
    FileToRead.BaseStream.Seek(0,SeekOrigin.Begin)
    while FileToRead.peek()>-1
      outputobject.text &= FileToRead.ReadLine()
    End While
    That should do the job.


  •  

    Posting Permissions

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