Question Problem to read datas from VB6 random access files

aeskan

Well-known member
Joined
Aug 10, 2011
Messages
63
Programming Experience
3-5
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.
 
Last edited:
Well, after surfing the web seems I found it. I Changed:

Dim Customer AsNewCustomers

To:

Dim Customer AsValueType = NewCustomers

And I add:

Dim Name As String = CType(Customer, Customers).CustomerName


The error disappeared, and nonce it's ok, till my return :eagerness:
 
Last edited:
Back
Top