this is messy but should work, the prior code had a problem because vb.net does something stupid with and, with most languages if the first is false then it doesn't evaluate the second, vb.net seems to ignore that so if you had and txt_name.text <> username(usernum)
and usernum was greater then 30 it would still try to evaluate the second statement and crash. Almost every other language I use would have detected that usernum > 30 and stopped there as the and was already false.
Dim loggedin As Boolean
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
usernum = 1
username(1) = "abc"
username(2) = "123"
username(3) = "efg"
loggedin = False
If txt_name.Text = username(usernum) Then
loggedin = True
Else
While usernum < 30
If loggedin = False Then
If txt_name.Text = username(usernum) Then
loggedin = True
Else
loggedin = False
End If
End If
usernum = usernum + 1
End While
If loggedin = False Then
MsgBox("Incorrect Username")
Else
MsgBox("Logged in")
End If
End If
End Sub