Link to home
Start Free TrialLog in
Avatar of Tim Turner
Tim TurnerFlag for United States of America

asked on

Changing User Defined Data Types over Time...

I have a question about UDTs that I can't find the answer to.... We have a UDT that we fill with data and then when program closes we save that UDT record to a file to reload it when program opens next time....

This works fine... My question is... Are UDT's accessed by the running code via the variable length declarations or by variable name...  If we use a record format for a year and then INSERT a new variable into the UDT will that mess up the reading of old records or does VB automagically read in the UDT based on the variable name declarations?  I suspect that it may mess up the saved UDTs if we add new variables into the UDT unless it is at the end of the UDT declaration????

Example:
Type myRecord
      myVar1(32) As Single
      myVar2(32) As Single
      myVar3(32) As Single
      myVar4(32) As Single
End Type

Now we save myRecord to a file as a binary data structure...  if we change the UDT by adding/inserting a new variable NOT AT THE END of the UDT will that mess up the reading of the records...
Type myRecord
      myVar1(32) As Single
      myVar2(32) As Single
      myVar2b(32) As Single  ' new var inserted
      myVar3(32) As Single
      myVar4(32) As Single
End Type

i.e. if we read in the above will it put the old myVar3 value into the new myVar2b value????

Also, if we declare the UDT above but at runtime need more space in the myVar1 array, can you use ReDim on a UDT variable???  and if so will it read in correctly next time... the reading of the data structures is done by code similar to:

   Open ClientFile For Random As 1 Len = Len(myRecord)
    Get #1, 1, myRecord
      On Error GoTo myFileReadErrorHandler
    Close

The saving of the UDT is done using something like:

    Open ClientFile For Random As 1 Len = Len(myRecord)
    Put #1, 1, myRecord
    Close #1

SOLUTION
Avatar of jmwheeler
jmwheeler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tim Turner

ASKER

jmwheeler: your insight was helpful. Thank you.

EDDYKT: although a pain because the code gets real long this solution was implemented to help reduce errors loading data saved under the OLD record types...

I'm awarding points to both of you. Thanks.