[RESOLVED] Why does this Array Check Return False?
I know this is not the best way to check for valid users but this is just for testing purposes and I am really stumped as to whay this function is returning a False every time.
Shouldn't a Bob, John or Steve return a True?
Code:
Public Class Form1
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim myName As String = "Bob"
If UserCheck(myName) Then
MessageBox.Show(UserCheck(myName).ToString)
Else
MessageBox.Show(UserCheck(myName).ToString)
Exit Sub
End If
End Sub
Function UserCheck(ByVal user As String) As Boolean
Dim ValidUsers() As String = {"Bob", "John", "Steve"}
Return ValidUsers.ToString.Contains("user")
End Function
End Class
Re: Why does this Array Check Return False?
Because ValidUsers.ToString will just return "System.String[]" not the list of array members.
I think this will do it;
Code:
Function UserCheck(ByVal user As String) As Boolean
Dim ValidUsers() As String = {"Bob", "John", "Steve"}
Return Array.IndexOf(ValidUsers, user) > -1
End Function
Re: Why does this Array Check Return False?
Thank you. That fixed it.