|
-
Dec 11th, 2000, 01:29 PM
#1
Thread Starter
Lively Member
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.
-
Dec 11th, 2000, 02:01 PM
#2
are you using the proper syntax to open the file?
Code:
f = freefile
Open MyFile for random as #f len = 50 '50 for example purposes
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.
[Edited by wossname on 12-11-2000 at 02:05 PM]
-
Dec 11th, 2000, 02:03 PM
#3
Frenzied Member
I think you should pass both the options
Code:
Put #1, , employee.ssn
put #1, , employee.age
or use CopyMemory to copy it in a byte array or something.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Dec 11th, 2000, 02:06 PM
#4
Jop, there is no need to do that, VB is capable of preserving UDT structure inside files.
-
Dec 11th, 2000, 02:10 PM
#5
Frenzied Member
mmkay...
vbuser1:
what error are you getting?
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Dec 11th, 2000, 04:13 PM
#6
Thread Starter
Lively Member
forgot something
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|