VB6: How are binary files encoded? using Put statement

后端 未结 3 1504
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 23:17

I have this code

  Open WritingPath & \"\\FplDb.txt\" For Random As #1 Len = Len(WpRec)
    For i = 1 To 99
      WpRec.WpIndex = FplDB(i, 1)
      WpRec         


        
3条回答
  •  生来不讨喜
    2020-12-11 23:48

    Add a reference to Microsoft.VisualBasic and use FilePut

    It is designed to assist with compatibility with VB6

    The VB6 code in your question would be something like this in C# (I haven't compiled this)

    Microsoft.VisualBasic.FileOpen (1, WritingPath & "\FplDb.txt", OpenMode.Random, 
      RecordLength:=Marshal.SizeOf(WpRec))
    for (i = 1; i < 100 ; i++) {
      WpRec.WpIndex = FplDB(i, 1)
      WpRec.WpName = FplDB(i, 2)
      WpRec.WpLat = FplDB(i, 3)
      WpRec.WpLon = FplDB(i, 4)
      WpRec.WpLatDir = FplDB(i, 5)
      WpRec.WpLonDir = FplDB(i, 6)
      Microsoft.VisualBasic.FilePut(1, WpRec, i)
    }
    Microsoft.VisualBasic.FileClose(1)
    

    I think Marshal.SizeOf(WpRec) returns the same value that Len(WpRec) will return in VB6 - do check this though.

提交回复
热议问题