Results 1 to 14 of 14

Thread: [RESOLVED] Change fields in UDT

Hybrid View

  1. #1
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Change fields in UDT

    Ugh. There is a much easier way.
    In the New UDT, add a version member as the first member of the UDT, numerical or unique string.
    Then simply open the file and read the first x bytes of the file to retrieve that version member.

    If the first member of the Old & New UDTs are string Dates (10 bytes), this is simple. The version member of the new udt is a non date value, i.e., "Ver1". Now read the first 10 bytes into a string and use IsDate(). If it returns false, then it isn't a date and therefore the new version

    Edited: This only solves the problem of which UDT to use for reading. If reading, using the the old UDT, and want to use the new UDT structure, you will have to convert from old to new. In future programs, it may be wise to simply append new members to a UDT vs trying to change member sizes. This is how Windows does it (most of the time). One version may read 10 members, but a newer version may read 15 members. The first member of a UDT is generally the size of the UDT. This way any app version can know where one udt starts & ends. Internally, the app knows how many bytes it needs per UDT for its purpose. The key difference here is that the UDT member sizes don't change, only the number of members change.
    Last edited by LaVolpe; Jan 5th, 2008 at 04:57 PM.

  2. #2

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Change fields in UDT

    Quote Originally Posted by LaVolpe
    Ugh. There is a much easier way.
    In the New UDT, add a version member as the first member of the UDT, numerical or unique string.
    Then simply open the file and read the first x bytes of the file to retrieve that version member.

    If the first member of the Old & New UDTs are string Dates (10 bytes), this is simple. The version member of the new udt is a non date value, i.e., "Ver1". Now read the first 10 bytes into a string and use IsDate(). If it returns false, then it isn't a date and therefore the new version

    Edited: This only solves the problem of which UDT to use for reading. If reading, using the the old UDT, and want to use the new UDT structure, you will have to convert from old to new. In future programs, it may be wise to simply append new members to a UDT vs trying to change member sizes. This is how Windows does it (most of the time). One version may read 10 members, but a newer version may read 15 members. The first member of a UDT is generally the size of the UDT. This way any app version can know where one udt starts & ends. Internally, the app knows how many bytes it needs per UDT for its purpose. The key difference here is that the UDT member sizes don't change, only the number of members change.
    I was hoping to get around opening 2 udt's into memory. Do you see any problem with using the files DateCreated to determine the udt to use?

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Change fields in UDT

    Quote Originally Posted by isnoend07
    I was hoping to get around opening 2 udt's into memory. Do you see any problem with using the files DateCreated to determine the udt to use?
    I don't see how you will get around it. The file will be in a format of one UDT or the other. In order to load them using VB's Get method, you would have to provide VB with the proper UDT structure.

    Eluded to in the previous post, another option is to simply convert old UDT to new UDT as needed. This still requires 2 UDTs initially. Read one & convert, read next and convert, etc. Yet another option is to read the file manually vs reading in UDTs by index, but is more work IMO and requires reading each UDT member individually.

    Please keep in mind what I said about the old app version not being able to read the new file version. I think this is another problem that isn't being addressed. There is no way the older version can determine if the file format is different. It will read the new version file incorrectly, period. The old version cannot be compatible with new format, but the new version can be compatible with old format.

    Regarding dates? I wouldn't rely on it. What if the old app version creates/updates a file, the new version app may mistakenly think the file is in the new format, no?

    Edited: I'd insert into the new UDT, as the first member, a Version member. This will definitively let you know which format the file is in by checking that member in IsDate() as described in previous post. Again the assumption is that the old UDT first member was also Date.
    Last edited by LaVolpe; Jan 5th, 2008 at 05:31 PM.

  4. #4

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Change fields in UDT

    Quote Originally Posted by LaVolpe
    I don't see how you will get around it. The file will be in a format of one UDT or the other. In order to load them using VB's Get method, you would have to provide VB with the proper UDT structure.

    Eluded to in the previous post, another option is to simply convert old UDT to new UDT as needed. This still requires 2 UDTs initially. Read one & convert, read next and convert, etc. Yet another option is to read the file manually vs reading in UDTs by index, but is more work IMO and requires reading each UDT member individually.

    Please keep in mind what I said about the old app version not being able to read the new file version. I think this is another problem that isn't being addressed. There is no way the older version can determine if the file format is different. It will read the new version file incorrectly, period. The old version cannot be compatible with new format, but the new version can be compatible with old format.

    Regarding dates? I wouldn't rely on it. What if the old app version creates/updates a file, the new version app may mistakenly think the file is in the new format, no?

    Edited: I'd insert into the new UDT, as the first member, a Version member. This will definitively let you know which format the file is in by checking that member in IsDate() as described in previous post. Again the assumption is that the old UDT first member was also Date.
    I don't see a problem with an old version trying to read a new version. The old version only creates old UDT's.
    How would i read the first 10 bytes of the file?
    Using this to open: Get miFilenumber, miIndex, gCustomer

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Change fields in UDT

    Quote Originally Posted by isnoend07
    I don't see a problem with an old version trying to read a new version. The old version only creates old UDT's.
    How would i read the first 10 bytes of the file?
    Using this to open: Get miFilenumber, miIndex, gCustomer
    Finally, an easy question
    Code:
    Dim sDate As String * 10
    Get miFilenumber, 1, sDate

  6. #6

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Change fields in UDT

    Quote Originally Posted by LaVolpe
    Finally, an easy question
    Code:
    Dim sDate As String * 10
    Get miFilenumber, 1, sDate
    I don't see what that tells me

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