Results 1 to 4 of 4

Thread: Add rows to 2D arrays

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Add rows to 2D arrays

    I have a 1 dimensional array, and I need to add it as a new line to a 2D array, how do I do this?

    I actually have many 1D arrays, but I need to make them 1 2D array. Then later pull them back out into 1D arrays.

    How do I do this?

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Add rows to 2D arrays

    Are they all (the 1D arrays) have the same demensions?
    Must you use a 2D array? If you don't have to use a 2d array, you can use a List to hold the 1D arrays.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Re: Add rows to 2D arrays

    Quote Originally Posted by stanav
    Are they all (the 1D arrays) have the same demensions?
    Must you use a 2D array? If you don't have to use a 2d array, you can use a List to hold the 1D arrays.

    Well I'm importing lines of comma separated text from a file then parsing it to a 1D array. Each post parsed line arrays will be of the same length, yes. Each array line carries information pertaining to file, however I'll have many lines in to import (one for each file recorded), so I cant pre-define each 1D array, for it could be on the order of hundreds of 1D arrays, and the total number arrays will constantly be changing as the number of line entries in the imported document change.

    How would I go about using a list?

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Add rows to 2D arrays

    Forget the array approach. Use a datatable. You can use ADO.Net to import a csv file to a datatable fairly easy. You can search this forum for code example of importing csv file to a datatable (search for something like "csv to datatable").

    On the other hand, if you want to use a list you can do this:
    Code:
    'Declare a list of string array
    Dim myList As New List(Of String())
    
    'Then when you read your csv file, after each line is converted to a 
    'string array, you add it to the list
    
    'your code to open the file here... I don't want to rewrite it
    line = reader.ReadLine()
    'Split the line at the comma's into an array, then add it to the list
    myList.Add(line.Split(","c))
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

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