|
-
Jun 18th, 2007, 03:37 PM
#1
Thread Starter
Hyperactive Member
[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
-
Jun 18th, 2007, 03:52 PM
#2
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
Last edited by Bulldog; Jun 18th, 2007 at 04:00 PM.
-
Jun 18th, 2007, 04:13 PM
#3
Thread Starter
Hyperactive Member
Re: Why does this Array Check Return False?
Thank you. That fixed it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|