I am attempting to design a username/password logon system using 2D arrays, but keep coming across the same problem, that the 'GetUpperBound' seems to cause many a problem. My code that I have constructed so far is below and ANY help would be very much appreciated! Thank you!
Public Class Form1
Dim i As Integer
Public PupilPasswords(2, 1) As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PupilPasswords(0, 0) = "Username"
PupilPasswords(0, 1) = "Password"
PupilPasswords(1, 0) = "Dave"
PupilPasswords(1, 1) = "Jones"
PupilPasswords(2, 0) = "Bob"
PupilPasswords(2, 1) = "Smith"
End Sub
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Do While i < 3
Dim Username As String = 0
Dim Password As String = 0
Username = PupilPasswords(i, 0)
Password = PupilPasswords(i, 1)
i = i + 1
Loop
For Me.i = 0 To PupilPasswords.GetUpperBound(i)
If txtUsername.Text = PupilPasswords(i, 0) And txtPassword.Text = PupilPasswords(i, 1) Then
Me.Hide()
Form2.Visible = True
Exit Sub
Else
If i = PupilPasswords.GetUpperBound(0) Then
MsgBox("Sorry wrong username and/or password")
End If
If txtUsername.Text = "" Or txtPassword.Text = "" Then
MsgBox("Sorry, please enter both your username and password")
End If
End If
Next
End Sub
End Class
Public Class Form1
Dim i As Integer
Public PupilPasswords(2, 1) As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PupilPasswords(0, 0) = "Username"
PupilPasswords(0, 1) = "Password"
PupilPasswords(1, 0) = "Dave"
PupilPasswords(1, 1) = "Jones"
PupilPasswords(2, 0) = "Bob"
PupilPasswords(2, 1) = "Smith"
End Sub
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Do While i < 3
Dim Username As String = 0
Dim Password As String = 0
Username = PupilPasswords(i, 0)
Password = PupilPasswords(i, 1)
i = i + 1
Loop
For Me.i = 0 To PupilPasswords.GetUpperBound(i)
If txtUsername.Text = PupilPasswords(i, 0) And txtPassword.Text = PupilPasswords(i, 1) Then
Me.Hide()
Form2.Visible = True
Exit Sub
Else
If i = PupilPasswords.GetUpperBound(0) Then
MsgBox("Sorry wrong username and/or password")
End If
If txtUsername.Text = "" Or txtPassword.Text = "" Then
MsgBox("Sorry, please enter both your username and password")
End If
End If
Next
End Sub
End Class