Results 1 to 3 of 3

Thread: [RESOLVED] Why does this Array Check Return False?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Resolved [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

  2. #2
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    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
  •  



Click Here to Expand Forum to Full Width