How do I check a list of numbers in VB6 if there is no INLIST function.

kevin33809
kevin33809 used Ask the Experts™
on
Hello

In VB.Net there is a function -- INLIST(), where I can put a list of numbers and check against what is in a variable.  Could someone show me in VB6 code how to check a list a numbers/chars against a given variable, that will function the same way as a InList function does?  Thanks.

Example:

if CoPlanID = INLIST(1, 10, 15, 20, 23, 50, 150) then
     var = "found it"
else
     var = "did not find it"
end if

......I need replace code for what I use the INLIST function for.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
' Firstly, put the INLIST items into an array

searchArray(0) = 1
searchArray(1) = 8
searchArray(2) = 22
searchArray(3) = 49
searchArray(4) = 81


'Check to see if element exists
If InStr(Join(searchArray), CoPlanID) > 0 Then
  'If the element is found code here
Else
  'If the element is not found code here
End If
Commented:
Try

coPlanID = 15
myString = "1, 10, 15, 20, 23, 50, 150"

sp = Split(myString, ",")

Dim found As Integer

For Each e In sp
    If coPlanID = Val(e) Then found = 1: Exit For
Next

MsgBox found

Open in new window

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
There's no InList() in VB.Net...

Author

Commented:
Thank you, Programmers.  You both had the Best Solution, so I split the reward.  I appreciate you help and quick response.  Thanks again.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial