I have created two arrays(Names() and Phones(), pretty self explanatory...). I want to be able to save on the fly, the content of textboxes into these arrays. I do not know how many elements will my arrays contain as it depends on the user's input.
Then I want to be able to look up a value from one array to the other i.e knowing a name I want to find the corresponding phone number and vice versa.
The first problem I am encountering is this: How can I check that the content of textboxes is actually stored in the arrays?
I have tried to have a couple of listboxes in there but I am not convinced 100% that it displays the content of the arrays...(see my code below) because I want to display the arrays content like this: [One array that is]
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Position As Long
Dim Names() As String
ReDim Preserve Names(UBound(Names))
For Position = LBound(Names) To UBound(Names)
and this doesn't work. It's giving me an "ArgumentNullException was unhandled. Values cannot be null. Parameter name: Argument 'Array' is Nothing"
I don't understand the meaning of this error. Could you please explain?
And second, how do I go about implementing the look up? I am thinking of sorting the elements in the array first(that's why I am trying to see the content of the arrays) , am I in the right track?
Any suggestions or guidance would be much appreciated.
Here is a fragment of code that I have so far:
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim Names() As String ' array to hold names
Dim Phones() As String ' array to hold phone numbers
Dim Dimensioned As Boolean ' to help check whether the array has been dimensioned
Dim strName As String ' to temporarily hold names
Dim strPhone As String ' to temporarily hold phone numbers
Dimensioned = False 'means the array has not been dimensioned
' get data from textboxes
strName = txtFullName.Text
strPhone = txtPhone.Text
If strName <> "" Then
If Dimensioned = True Then
ReDim Preserve Names(0 To UBound(Names) + 1)
ReDim Preserve Phones(0 To UBound(Phones) + 1)
ReDim Names(0 To 0)
ReDim Phones(0 To 0)
Dimensioned = True
Names(UBound(Names)) = strName
Phones(UBound(Phones)) = strPhone
txtFullName.Text = ""
txtPhone.Text = ""
Loop Until strName = ""