what i am attempting to do is make sure that the corresponding username and password is correct and if any1 would like to give me a way to detect how many usernames i have in the array so i can tell it when to stop looking this would help me so much for my major work thanks

Replies To: password and username array problem

Re: password and username array problem

Posted 16 February 2013 - 09:55 PM

It's an array... so use a for loop to go through each name, see if it matches the password, KEEP TRACK OF THE INDEX YOU ARE ON, and if it is found check to see if that corresponding index in the password array matches.

Re: password and username array problem

Posted 17 February 2013 - 07:59 AM

zaneg, on 16 February 2013 - 11:27 PM, said:

what i am attempting to do is make sure that the corresponding username and password is correct and if any1 would like to give me a way to detect how many usernames i have in the array so i can tell it when to stop looking this would help me so much for my major work thanks

To check how many names are in (username) you can use (username.length). For example username.length would equal 3 in your array. However arrays are zero indexed meaning the 1st name would be stored in username(0), 2nd name in username(1), and so on. This is an example of how you could do it. You may want to do it a different way but, this will give you an idea of how you could check them and see a way you can get the count of names in your array.

Public Class Form1
Dim username() As String = {"user", "userr", "userrr"}
Dim password() As String = {"pass", "pass", "pass"}
Private Sub Button_Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Login.Click
Dim matched As Boolean = False
For count = 0 To username.Length - 1 'username.length counts the number of strings in username
If txtuser.Text = username(count) And txtpass.Text = password(count) Then
matched = True
Exit For 'The name & password match so no need to check the rest.
End If
Next
If matched = True Then
MessageBox.Show("Show Play Form")
'play.Show()
Else
MessageBox.Show("incorrect")
Me.Close()
End If
End Sub
End Class