Help needed converting VB6 file IO code sample to VB.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rory Becker

    Help needed converting VB6 file IO code sample to VB.net

    The following code is being used in a VB6 program to read and write a simple
    binary file.

    I need to move things into the 21st century and recode this in VB.Net

    The new VB.Net program will need to continue to operate in the same enterprise
    level situation.

    Rollout will be slow and so for the moment the new code will have to be able
    to read and write these files in the exact same format as the Old VB6 code.

    The code is:
    -------------------------------------------------------------
    Public Type TransferHeader
    Hub As String
    Version As Long ' I appreciate that this should be an Integer in VB.Net
    End Type

    Private Sub SetFileHeaderDa ta(Filename As String, Data As TransferHeader)
    Dim DataFile As Byte
    DataFile = FreeFile()
    Open Filename For Binary Access Write As #DataFile
    Put #DataFile, , Data
    Close #DataFile
    End Sub

    Private Function GetHeaderOfFile (HeaderFile As String) As TransferHeader
    Dim TempHeader As TransferHeader
    Dim DataFile As Byte
    DataFile = FreeFile()
    Open HeaderFile For Binary Access Read As #DataFile
    Do Until EOF(DataFile)
    Get #DataFile, , TempHeader
    If Len(TempHeader. Hub) 0 Then
    GetHeaderOfFile = TempHeader
    End If
    Loop
    Close #DataFile
    End Function
    -------------------------------------------------------------

    Does anyone know how to do this?

    Many thanks in advance.

    --
    Rory


  • cfps.Christian

    #2
    Re: Help needed converting VB6 file IO code sample to VB.net

    While I'm not imminently familiar with VB6 it looks like you need to
    look around for the FileStream, StreamWriter, and SteamReader
    objects. The StreamReader can open the file and using the
    StreamReader.Pe ek() method you can see if there are any more rows left
    (Peek returns -1 if EOF). Then use StreamReader.Re adLine to pull the
    data out of the row.

    Pretty sure thats what you're looking for.

    Comment

    • zacks@construction-imaging.com

      #3
      Re: Help needed converting VB6 file IO code sample to VB.net

      On Apr 22, 9:16 am, "cfps.Christian " <ge0193...@otc. eduwrote:
      While I'm not imminently familiar with VB6 it looks like you need to
      look around for the FileStream, StreamWriter, and SteamReader
      objects.  The StreamReader can open the file and using the
      StreamReader.Pe ek() method you can see if there are any more rows left
      (Peek returns -1 if EOF).  Then use StreamReader.Re adLine to pull the
      data out of the row.
      >
      Pretty sure thats what you're looking for.
      Plus the BinaryReader and BinaryWriter classes.

      Comment

      • Rory Becker

        #4
        Re: Help needed converting VB6 file IO code sample to VB.net

        >While I'm not imminently familiar with VB6 it looks like you need to
        >look around for the FileStream, StreamWriter, and SteamReader
        >objects. The StreamReader can open the file and using the
        >StreamReader.P eek() method you can see if there are any more rows
        >left
        >(Peek returns -1 if EOF). Then use StreamReader.Re adLine to pull the
        >data out of the row.
        >Pretty sure thats what you're looking for.
        >>
        Plus the BinaryReader and BinaryWriter classes.
        Cheers to you both. I now have a working sample which uses a Binary reader
        to retrieve the details from the 1st record in the data. and extract the
        Int and the String.

        I have managed to resolve the fact that bytes 2 through 6 are the string
        I need (All strings will be 4 chars) and the next 2 are the 32 bit integer
        I need.

        Can someone tell me what the first 2 (values 04 and 00) and last 2 bytes
        (values 00 and 00) are for?

        Is this to indicate encoding and end of record?

        Once I know what these codes mean I should be able to construct the "Writer"
        half of the equation.

        Thanks once again

        --
        Rory


        Comment

        Working...