相当于 VB6 至 2022 VB.NET "Get"语句



我有一些VB6代码需要迁移到VB.NET,我想查询这几行代码,看看是否有办法在.NET.中实现它们

Get语句不再受支持,因此如何替换它?

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

我没有在网上找到任何有用的东西,我从来没有在vb6 中编码

二进制访问的基本代码,其中Get语句等效为ReadByte((、ReadInt16((,将是:

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

最新更新