4

I have some VB6 code that needs to be migrated to VB.NET, and I wanted to inquire about this lines of code, and see if there is a way to implement them in .NET.

Get statements are no longer supported so how can I replace it?

For i = 0 To ntc(j) - 1
    Get 4, , sounding(i)
    Get 4, , ullage(i)
    Get 4, , volc(i)
    Get 4, , lcgc(i)
    Get 4, , tcgc(i)
    Get 4, , vcgc(i)
    Get 4, , tfsm(i)
    Get 4, , lfsm(i)
Next i

I haven't found anything useful online and I never coded in vb6

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
MattL99
  • 137
  • 5
  • 3
    The direct equivalent is [`Microsoft.VisualBasic.FileSystem.FileGet`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.filesystem.fileget?view=net-6.0), if you don't want to rewrite it completely. – GSerg Feb 07 '22 at 18:04

1 Answers1

1

A basic code for binary access, in which Get statement equivalent would be ReadByte(), ReadInt16(), ... , would be:

Sub Main()
    ' add file name to temp folder:
    Dim sfile As String = Path.GetTempPath + "test.dat"
    WriteIntoAFile(sfile)
    ReadFromAFile(sfile)
    Console.WriteLine("Press enter to exit.")
    Console.ReadLine()
End Sub
Sub WriteIntoAFile(file As String)
    Try
        Dim fs As New FileStream(file, FileMode.OpenOrCreate, FileAccess.Write)
        Dim bw As New BinaryWriter(fs)
        Dim dat As Int32 = 20
        For i As Int32 = 0 To 5
            bw.Write(dat - i) ' write Int32 values
        Next
        bw.Close()
    Catch ex As Exception
        MsgBox(ex.ToString, MsgBoxStyle.Exclamation, "Found an error")
    End Try
End Sub
Sub ReadFromAFile(file As String)
    Try
        Dim fs As New FileStream(file, FileMode.Open, FileAccess.Read)
        Dim br As New BinaryReader(fs)
        Dim dat As Int32
        For i = 0 To 5
            dat = br.ReadInt32()
            Console.WriteLine(dat.ToString)
        Next
        br.Close()
    Catch ex As Exception
        MsgBox(ex.ToString, MsgBoxStyle.Exclamation, "Found an error")
    End Try
End Sub
Xavier Junqué
  • 350
  • 2
  • 5