Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15628

Check if a array contains value from other array

$
0
0
Hi, I want to check if what a user enter on a textbox is present on a array. The code below do that, by the way, the Q("TXB_CODE_ING") mean it query the value of the textbox named "TXB_CODE_ING".It is
a way to query the value that come from a IDE from where I work.

So the code below will work if the user enter a option that exist in the allOptions array, but what I want to do is, if the user enter a option that do not exist, it exit the loop and display a error message.
Code:

Dim allOptions() As String = {"PP","AP","WP","TX","TZ","TY"}
Dim arrayVal() As String =  Q("TXB_CODE_ING").split("-")
For i As Integer = 0 To  arrayVal.length -1
        For j As Integer = 0 To allOptions.length -1
                If  (allOptions(j).Contains( arrayVal(i))) Then
                        msgbox("we find it at position " &j)
                        Exit For
                End If 
        Next 
Next

So i have try this,just added a Not after the if
Code:

Dim allOptions() As String = {"PP","AP","WP","TX","TZ","TY"}
Dim arrayVal() As String =  Q("TXB_CODE_ING").split("-")
For i As Integer = 0 To  arrayVal.length -1
        For j As Integer = 0 To allOptions.length -1
                If  Not  (allOptions(j).Contains( arrayVal(i))) Then
                        msgbox("Invalid Option " &i)
                        Exit For
                End If 
        Next 
Next

But that don't work, because the options that suppose to be ignored because they are valid are considered invalid and they will still be display.. hope its understandable.. :D

If anyone can help me with that!

Thank!

Viewing all articles
Browse latest Browse all 15628

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>