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?
Re: Load data into 2-dimensional array
vb Code:
Dim lines As String() = IO.File.ReadAllLines("file path here")
'Load the data into the TextBox.
myTextBox.Lines = lines
'Create a new 2D array to store the data.
Dim upperBound As Integer = lines.GetUpperBound(0)
Dim numbers(1, upperBound) As Integer
Dim lineParts As String()
Dim number As Integer
For rowIndex As Integer = 0 To upperBound Step 1
lineParts = lines.Split(" "c)
For columnIndex As Integer = 0 To 1
If lineParts.Length > columnIndex AndAlso _
Integer.TryParse(lineParts(columnIndex), number) Then
numbers(columnIndex, rowIndex) = number
End If
Next columnIndex
Next rowIndex