Hi vb.net folks
I had a program in Vb6 years ago, which nowadays, naturally wanted to upgrade it to Vb.Net. Subsequently I tryed to upgrade its old archives and self-made data files, but on the spot I encountered to the challenge of read data from Vb6 random access files in Vb.Net! For ordinary random access files I have no problem, but when the file contains self-defined Type variables my problem begins. My Vb6 and Vb.Net sample codes also the Error are as below. Any suggestion will be appreciated.
Vb6 code:
Private Type Customers
FormID As String * 5
CustomerName As String * 60
CustomerTel As String * 30
RegNumber As String * 6
V1 As Byte
V2 As Byte
V3 As Byte
V4 As Byte
V5 As Byte
End Type
Dim Customer As Customers
fileNum = FreeFile
Open "Customers.Dat" For Random As fileNum Len = Len(Customer)
Get fileNum, lFormID, Customer
Close fileNum
Vb.Net code:
StructureCustomers
<VBFixedString(5)> Dim FormID AsString
<VBFixedString(60)> Dim CustomerName AsString
<VBFixedString(30)> Dim CustomerTel AsString
<VBFixedString(6)> Dim RegNumber AsString
Dim V1 AsByte
Dim V2 AsByte
Dim V3 AsByte
Dim V4 AsByte
Dim V5 AsByte
EndStructure
Dim Customer AsNewCustomers
Dim FileNum AsInteger = FreeFile()
FileOpen(FileNum, "Customers.Dat", OpenMode.Random, OpenAccess.Read, , Len(Customer))
FileGet(FileNum, Customer, lFormID)
FileClose(FileNum)
Note: Customer in FileGet statement is underlined beacuse of error. And error in the error list of vb.net editor is as below:
Error 1: Option Strict On disallows narrowing from type 'System.ValueType' to type 'WindowsApplication1.Customers' in copying the value of 'ByRef' parameter 'Value' back to the matching argument. F:\Visual studio 2010\Projects\Convert\Form1.vb 142 47 Convert
Note2: MSDN says "Supply each ByRef argument in the procedure call with the same data type as the declared type, or turn Option Strict Off." Does any body know How to "Supply each ByRef argument in the procedure call..." in this specific case, and if I turn Option Strict Off, doesn't it do any big changes to my program? Thanks.
I had a program in Vb6 years ago, which nowadays, naturally wanted to upgrade it to Vb.Net. Subsequently I tryed to upgrade its old archives and self-made data files, but on the spot I encountered to the challenge of read data from Vb6 random access files in Vb.Net! For ordinary random access files I have no problem, but when the file contains self-defined Type variables my problem begins. My Vb6 and Vb.Net sample codes also the Error are as below. Any suggestion will be appreciated.
Vb6 code:
Private Type Customers
FormID As String * 5
CustomerName As String * 60
CustomerTel As String * 30
RegNumber As String * 6
V1 As Byte
V2 As Byte
V3 As Byte
V4 As Byte
V5 As Byte
End Type
Dim Customer As Customers
fileNum = FreeFile
Open "Customers.Dat" For Random As fileNum Len = Len(Customer)
Get fileNum, lFormID, Customer
Close fileNum
Vb.Net code:
StructureCustomers
<VBFixedString(5)> Dim FormID AsString
<VBFixedString(60)> Dim CustomerName AsString
<VBFixedString(30)> Dim CustomerTel AsString
<VBFixedString(6)> Dim RegNumber AsString
Dim V1 AsByte
Dim V2 AsByte
Dim V3 AsByte
Dim V4 AsByte
Dim V5 AsByte
EndStructure
Dim Customer AsNewCustomers
Dim FileNum AsInteger = FreeFile()
FileOpen(FileNum, "Customers.Dat", OpenMode.Random, OpenAccess.Read, , Len(Customer))
FileGet(FileNum, Customer, lFormID)
FileClose(FileNum)
Note: Customer in FileGet statement is underlined beacuse of error. And error in the error list of vb.net editor is as below:
Error 1: Option Strict On disallows narrowing from type 'System.ValueType' to type 'WindowsApplication1.Customers' in copying the value of 'ByRef' parameter 'Value' back to the matching argument. F:\Visual studio 2010\Projects\Convert\Form1.vb 142 47 Convert
Note2: MSDN says "Supply each ByRef argument in the procedure call with the same data type as the declared type, or turn Option Strict Off." Does any body know How to "Supply each ByRef argument in the procedure call..." in this specific case, and if I turn Option Strict Off, doesn't it do any big changes to my program? Thanks.
Last edited: