Skip to content

How can i stored values to 2D array variable in vb.net

karthick babu

Asked Dec 3, 2007, 8:51 PM EST1 answer
Share
LinkedInX

Hi

Is Possible to store a value to declared Variable from Text Box at run time. I want to store a value from Text Box in 2 dimension array. First Value can be sotred in variable(0,0). If i press enter text box will be cleared and get another number and it stored in variable(0,1) and so on

I try the code as below but not working. I write this in Text Box KeyDown Event. If not in which event we write the code


Try
   If e.KeyCode = Keys.Enter Then
        For i As Integer = 0 To 1
                For j As Integer = 0 To 1
                        FirstMatrixArray(i, j) = val(txtInput.Text)
                        txtInput.Text = ""
                        txtInput.Focus()
                    Next
                Next
            End If
    Catch ex As Exception
         MessageBox.Show(ex.Message)
End Try

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Is the size of the 2d array known?  If not, i don't think this is the way to go.  Try using an arraylist instead as it is dynamic - you can just add items to it and it will expand. 
    0