Results 1 to 2 of 2

Thread: Load data into 2-dimensional array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    66

    Load data into 2-dimensional array

    Public Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
    Dim streamline As System.IO.StreamReader
    Dim Txt As String = ""

    OpenFileDialog1.FileName = "Select File"
    If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
    Return
    End If
    OpenFileName = OpenFileDialog1.FileName
    streamline = New System.IO.StreamReader(OpenFileName)
    Do Until streamline.EndOfStream
    Txt = Txt & streamline.ReadLine & vbCrLf


    Loop
    streamline.Close()
    TextBox1.Text = Txt
    End Sub


    So this code loads a bunch of numbers into a textbox......how do i load them into an array (two dimensional)

    545435345 65
    345345345 45

    basically my goal is two have to input boxes, and when the user types in the left number, the second box displays the corresponding number...

    any ideas?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Load data into 2-dimensional array

    vb Code:
    1. Dim lines As String() = IO.File.ReadAllLines("file path here")
    2.  
    3. 'Load the data into the TextBox.
    4. myTextBox.Lines = lines
    5.  
    6. 'Create a new 2D array to store the data.
    7. Dim upperBound As Integer = lines.GetUpperBound(0)
    8. Dim numbers(1, upperBound) As Integer
    9. Dim lineParts As String()
    10. Dim number As Integer
    11.  
    12. For rowIndex As Integer = 0 To upperBound Step 1
    13.     lineParts = lines.Split(" "c)
    14.  
    15.     For columnIndex As Integer = 0 To 1
    16.         If lineParts.Length > columnIndex AndAlso _
    17.            Integer.TryParse(lineParts(columnIndex), number) Then
    18.             numbers(columnIndex, rowIndex) = number
    19.         End If
    20.     Next columnIndex
    21. Next rowIndex
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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