How do I place a user-defined type in a binary file?
example:
Private Type people
age As integer
ssn As Long
End Type
dim employee as people
employee.age=36
employee.ssn=643649832
Put #1, , employee 'gives me an error
Any suggestions? Thanks.
Printable View
How do I place a user-defined type in a binary file?
example:
Private Type people
age As integer
ssn As Long
End Type
dim employee as people
employee.age=36
employee.ssn=643649832
Put #1, , employee 'gives me an error
Any suggestions? Thanks.
are you using the proper syntax to open the file?
otherwise, i notice that you have declared the type as private. Are you trying to PUT the variable from another module / form? Try making it public instead of private, unless it interferes with the structure of your program.Code:f = freefile
Open MyFile for random as #f len = 50 '50 for example purposes
[Edited by wossname on 12-11-2000 at 02:05 PM]
I think you should pass both the options
or use CopyMemory to copy it in a byte array or something.Code:Put #1, , employee.ssn
put #1, , employee.age
Jop, there is no need to do that, VB is capable of preserving UDT structure inside files.
mmkay...
vbuser1:
what error are you getting?
I missed a step, there is an enumeration for age.
ex.
enum agetype
young
old
end enum
Private Type people
age As agetype
ssn As Long
End Type
...
employee.age=young
put #1, , employee
The error I get is : Can't Get or Put an object reference variable or a variable of user-defined type containing an object reference.