Need help with .Equals method

I have written the following code. My problem is that I am trying to validate user input to check if it is a valid member of an array. Can I check the entire array at one time or do I have to check each element. The array is:

arrSKU = New String() {"AA123", "AA223", "AD543", "AD555", "BD666"}

My code is:

Dim k As Integer = 0
Dim bolFound As Boolean = False

Do While (k <= 4 And Not bolFound)
If txtSKU.Text.Equals(arrSKU) Then
bolFound = True
Else
k = k + 1
End If
Loop

If (bolFound) Then
MessageBox.Show("SKU is valid", "Title Bar Label", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Invalid SKU", "Title Bar Label", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

I have compiled my code with no errors but when I run it I always get the "Invalid SKU" message even if the entered SKU matches an element in the array.

Any help on this would be appreciated.

Comments

  • : I have written the following code. My problem is that I am trying to validate user input to check if it is a valid member of an array. Can I check the entire array at one time or do I have to check each element. The array is:
    :
    : arrSKU = New String() {"AA123", "AA223", "AD543", "AD555", "BD666"}
    :
    : My code is:
    :
    : Dim k As Integer = 0
    : Dim bolFound As Boolean = False
    :
    : Do While (k <= 4 And Not bolFound)
    : If txtSKU.Text.Equals(arrSKU) Then
    : bolFound = True
    : Else
    : k = k + 1
    : End If
    : Loop
    :
    : If (bolFound) Then
    : MessageBox.Show("SKU is valid", "Title Bar Label", _
    : MessageBoxButtons.OK, MessageBoxIcon.Information)
    : Else
    : MessageBox.Show("Invalid SKU", "Title Bar Label", _
    : MessageBoxButtons.OK, MessageBoxIcon.Information)
    : End If
    :
    : I have compiled my code with no errors but when I run it I always get the "Invalid SKU" message even if the entered SKU matches an element in the array.
    :
    : Any help on this would be appreciated.
    :

    It would be easier to do this ...

    [code]
    Dim bolFound As Boolean = (arrSku.IndexOf(txtSKU.Text.Trim) <> -1)
    ...
    [/code]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion