'Equivalent of "Get" statements VB6 to VB.NET 2022
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
Solution 1:[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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Xavier Junqué |
