Results 1 to 5 of 5

Thread: Dynamically allocated arrays -> newbie

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2003
    Location
    Chicagoland
    Posts
    92

    Dynamically allocated arrays -> newbie

    Hi all. I'm just starting to learn VB.NET and I have a problem. I'm trying to read in a text file, parse it, and display the results. Here is an example of what my text files might look like:

    Code:
    ABC   Field1Field2Field3Field4
    BCD   Field1Field2Field3Field4Field5Field6
    CDE   Field1Field2Field3Field4Field5
    XYZ   Field1Field2Field3Field4Field5Field6...
    TUV   Field1Field2Field3Field4Field5Field6...
    XXX   Field1Field2Field3Field4Field5Field6...
    ...
    Basically there is a header before each line that is a set length. Based on the header, I know how many fields there are and how long each field is (there is no common field length, that is Field1 could be 10 characters and Field2 could be 3 characters and Field1 of another line could be 25 characters). I could have as few as five lines and as many as 100 or more.

    My problem is displaying the results. My plan is to read the lines in and display them to seperate tab pages (line ABC would go to the first tab page, BCD would go to the next, etc.). Generating the controls is no big deal. I can figure that out myself. I am trying to get each field its own TextBox. The only way I know how to do it is like:

    Code:
    Dim txtBox() As TextBox = {TextBox1, TextBox2, ... TextBoxN}
    Dim index As Integer
    
    Do
       InputString = InputFile.GetLine()
       tmpString = Mid(InputString, StrngIndex, Length
       txtBox(index).Text = tmpString
    Loop While Not InputString Is Nothing
    Or something like that. That's not quite right, but the point is that as I read in the line, I need to make enough TextBoxes to hold each field. Also, as I populate pages, the TextBox index will not start at one. For instance on the third page, they may start at 20 or something.

    Is this at all clear? Is there any hope? Is there a better way to do it?

    Thanks

  2. #2
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Question

    Are you trying to do something like:

    ~ open file
    ~ read header line
    ~ calculate number of fields in the data (next) row.
    ~ create above number of text boxes
    ~ read in data row
    ~ apply data to text boxes
    ~ read next header line
    ~ etc...

    ??
    ~Peter


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2003
    Location
    Chicagoland
    Posts
    92
    Essentially, yes.

    I simplified my sample in my first post, but if I could get some help on how to do that, I'd be set.

    If you want more specifics:
    The ABC in the sample datafile is the header. Using a switch statement, I open a second file that tells me how many characters are in each field. It is just a list of numbers, one per line, that I use for Mid() and to update the pointer that points to the start of the next field (also for Mid()). So my general flow will be something like:
    Code:
    read in line from datafile
    get header using Mid()
    use header to find proper .dat file
    loop until end of line from datafile
       read in fieldsize from .dat
       get field from datafile
       make label to tell me what field is
       make textbox with data in it
       make textbox with fieldsize in it
    end loop
    I guess I really don't need an array setup. I just do it on the fly.

    Again, is there a better way, like something other than textboxes, that might be easier? We're talking hundreds of textboxes here.

  4. #4
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    can you give an sample file and explain what the header describes?
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2003
    Location
    Chicagoland
    Posts
    92
    Unfortunately no. This is for work and I don't think I could do that. All the header does is tell me what kind of data is in the rest of the line. For example, in my first post, ABC would map to some documentation that would tell me that there are 4 fields and field1 is X characters long and that field2 is Y characters long, etc. In the next line, BCD show that there are 6 fields where field1 is N characters long and field2 is M characters long, etc.

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