I am using a user-defined data type to define a record (e.g. Customer name, Customer ID). When I put both fields of the record as strings I get no problem writing the record to a direct access file. But when I put the ID as an integer, the file becomes unreadable and data can't be retrieved again.
e.g.
Private Type CustomerType
CustomerID As Integer
CustomerName As String * 10
End Type
Dim Customer As CustomerType
Open App.Path & "\Customers.dat" for Random As #1 Len = Len(Customer)
NumberOfRecords = LOF(1) / Len(Customer)
Put #1, NumberOfRecords + 1, Customer
Close #1
I was advised to convert the text box that contained the customer ID to an integer before assigning a variable to it.....
Customer.CustomerID = CInt(txtCustomerID.Text)
but it didn't help. MsgBox (VarType(Customer.CustomerID)) showed 2, which is an integer. So what is the problem? Why does it write the ID to my direct access file as a square block instead of a visible number?
2006-11-17
21:14:15
·
3 answers
·
asked by
Older&Wiser
5
in
Computers & Internet
➔ Programming & Design
Thanks Tamayi M and Justme. I'm digesting your answers.
Tamayi M - my file is the same if I delete it and let the program create another one. I understand what you said about CInt and I'll follow those links. Ta. I'm not quite sure about VarType though, because although I understood what you said about 2 and "2" being different things, MsgBox(2) and MsgBox("2") wouldn't give the same result unless there was a variable called 2, that held the value 2. And VarType should show whether you have "2" or 2 in a variable.
Justme - I had tried assuming that my file should look just like it does - but the trouble is, retrieving the data from it gives incorrect figures. I can't even see where some of them come from. What do you mean by opening the file as a binary file - You mean as well as opening it for random access or instead of, I need to say it's a binary file?
2006-11-19
08:03:14 ·
update #1