CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2011
    Posts
    14

    Change Data Structure Length during VB6 runtime?

    Hello:
    I need to create a data structure and the file has a single field per record, and it will be fixed length for each record.

    For example FILE1.TXT
    1234
    3456
    6789

    FILE2.TXT
    65432
    76543
    34567

    FILE3.TXT
    5467812
    6583945
    6958485

    Is there a way to dynamically change the data structure during VB6 runtime?
    The lenght is fixed inside a given file, but each file can have a different length from 3-10.

    'Record data structure
    Type tRec
    strTMK As String * 5 (if FILE1.TXT this is 4, if FILE2.TXT this is 5, if FIL3.TXT this is 7, etc)
    CR_LF As String * 2
    End Type

    Your help is much appreciated.

    thanks
    kp

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Change Data Structure Length during VB6 runtime?

    Yes and no, If the intention is to use a binary read of x bytes into the given string then you could do so by not assigning a length to the string when it is dimmed then initialize it later to the size needed.

    Code:
    Dim MyString as string
    MyString = String(X, " ")
    Get #1,,MyString
    Where x is the number of bytes you wish to have in the string. The get statement will read the number of bytes that are in the string so you simply change the value of X to read a different number of bytes.


    Edit
    If you want to use structures of different sizes you do this by defining each of those structures and then using the one that you will need for the given task.
    Last edited by DataMiser; December 23rd, 2011 at 03:02 AM.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Change Data Structure Length during VB6 runtime?

    Yes, right.
    But if your file is line oriented anyway, and you don't want to do random access you can read it on a line by line base, where the data structure has dynamic strings
    Come to think about it, you do not need a data structure at all.
    Storing the CrLf is redundant anyway.

    All depends if you read all the data into memory or if you want to do random access to the files.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Change Data Structure Length during VB6 runtime?

    From the other thread I gather that the goal is to be able to write to the file at a given location. Random access or Binary is the best way to do so with Random acess being the most simple.

    I provided a small sample in the other thread. This sample could be adapted using the string sizing I have shown in this thread to a function that could take the size as a parameter and work with the files in question.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Change Data Structure Length during VB6 runtime?

    Yes. It's a good sample.
    I just wrote this post before noticing the other thread.

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

Featured