Results 1 to 6 of 6

Thread: Open as Binary , gr !

  1. #1

    Thread Starter
    Hyperactive Member mastermind94's Avatar
    Join Date
    Jun 2000
    Location
    Montréal, Canada
    Posts
    441

    Angry Open as Binary , gr !

    i'm stuck on this since a few days
    i need the translation from VB6 to VB.NET

    Code:
    Open FileName For Binary As #1
    Get #1, CurrentPOS, strData
    Close #1
    i tried with the IO class and FileOpen but, never worked!

    thanks

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Try something like this:
    VB Code:
    1. Dim fs As IO.FileStream = New IO.FileStream(filename, IO.FileMode.Open)'open file
    2.         Dim br As New IO.BinaryReader(fs)'read as binary
    3.         Dim b() As Byte = br.ReadBytes(fs.Length)'now the contents are in a byte array
    4.         Dim str As String = System.Text.Encoding.ASCII.GetString(b)'convert byte array to string
    5.         br.Close()'close file
    6.         fs.Close()

  3. #3
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    or to go the old way in .net it is

    VB Code:
    1. Dim intFile as integer = FreeFile
    2.  
    3. FileOpen(intFile, "C:\bob.txt", OpenMode.Binary, OpenAccess.Read)
    4.  
    5. FileClose(intFile)

  4. #4

    Thread Starter
    Hyperactive Member mastermind94's Avatar
    Join Date
    Jun 2000
    Location
    Montréal, Canada
    Posts
    441
    Originally posted by rudvs2
    or to go the old way in .net it is

    VB Code:
    1. Dim intFile as integer = FreeFile
    2.  
    3. FileOpen(intFile, "C:\bob.txt", OpenMode.Binary, OpenAccess.Read)
    4.  
    5. FileClose(intFile)

    Rudvs2 > yea i tried that but, how can i use the "GET #1, FilePosition, strData". I didnt figure it out...

    Edneeis > Thanks, i'll try to work it out tonite.


    thanks alot guys. ;p

  5. #5
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    The get statement has changed to fileget

    FileOpen(1, "C:\TESTFILE.txt", OpenMode.Binary)
    FileGet(FileNumber, Data,RecordNumber)


    Jeremy

  6. #6

    Thread Starter
    Hyperactive Member mastermind94's Avatar
    Join Date
    Jun 2000
    Location
    Montréal, Canada
    Posts
    441
    ataboy Jeremy...
    thanks alot

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