Hi
I am populating an array using the code below, which works fine and I can see the correct contents in the array in the locals window. The code is called from the forms on-load event.
However, I then need to reference this array on the click of a button and compare an element of it to the contents of a text box, but I seem to be missing something obvious. Here is what I have:
Private Type typPerson
UsNm As String * 20
FName As String
Sname As String
PIN As Integer
End Type
Private Sub PopulateArray()
Dim aryUsers() As typPerson
Dim intCount As Integer
intCount = 1
Open "C:\Nigel\VB6\vbTestNames.csv" For Input As #1
ReDim aryUsers(intCount)
Do Until EOF(1)
Input #1, aryUsers(intCount).UsNm
Input #1, aryUsers(intCount).FName
Input #1, aryUsers(intCount).Sname
Input #1, aryUsers(intCount).PIN
intCount = intCount + 1
ReDim Preserve aryUsers(intCount)
Loop
'Debug.Print UBound(aryUsers)
End Sub
Private Sub cmdLogin_Click()
Dim aryUsers()
Dim i As Integer
i = 1
Do Until i = 9
If txtUserName.Text = aryUsers(i).UsNm Then
MsgBox "Match"
Else
MsgBox "No Match"
End If
i = i + 1
Loop
End Sub
Using this and holding the cursor over 'aryUsers(i)' shows nothing i.e. it doesn't seem to recognise the array- the error message when I run it says 'subscript out of range'. Where am I going wrong please?
Nigel
Didn't someone say work is supposed to be fun? They didn't have computers then I guess....
I am populating an array using the code below, which works fine and I can see the correct contents in the array in the locals window. The code is called from the forms on-load event.
However, I then need to reference this array on the click of a button and compare an element of it to the contents of a text box, but I seem to be missing something obvious. Here is what I have:
Private Type typPerson
UsNm As String * 20
FName As String
Sname As String
PIN As Integer
End Type
Private Sub PopulateArray()
Dim aryUsers() As typPerson
Dim intCount As Integer
intCount = 1
Open "C:\Nigel\VB6\vbTestNames.csv" For Input As #1
ReDim aryUsers(intCount)
Do Until EOF(1)
Input #1, aryUsers(intCount).UsNm
Input #1, aryUsers(intCount).FName
Input #1, aryUsers(intCount).Sname
Input #1, aryUsers(intCount).PIN
intCount = intCount + 1
ReDim Preserve aryUsers(intCount)
Loop
'Debug.Print UBound(aryUsers)
End Sub
Private Sub cmdLogin_Click()
Dim aryUsers()
Dim i As Integer
i = 1
Do Until i = 9
If txtUserName.Text = aryUsers(i).UsNm Then
MsgBox "Match"
Else
MsgBox "No Match"
End If
i = i + 1
Loop
End Sub
Using this and holding the cursor over 'aryUsers(i)' shows nothing i.e. it doesn't seem to recognise the array- the error message when I run it says 'subscript out of range'. Where am I going wrong please?
Nigel
Didn't someone say work is supposed to be fun? They didn't have computers then I guess....