Results 1 to 6 of 6

Thread: place user-defined type in binary file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    California, USA
    Posts
    111
    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.

  2. #2
    Guest
    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]

  3. #3
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    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.

  4. #4
    Guest
    Jop, there is no need to do that, VB is capable of preserving UDT structure inside files.

  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    mmkay...
    vbuser1:
    what error are you getting?

    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    California, USA
    Posts
    111

    Question 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
  •  



Click Here to Expand Forum to Full Width