Check if a variable belongs to a set of values

Solved
panda -  
 Panda -
Hello,

I just want to check with a condition if my variable belongs to a set of values.
Of course, I can do:

If Var = 1 or Var = 5 or Var = 12 or..... then

but it's a bit tedious when there are a lot of tests.

There should be something like

if Var = (or(1, 5, 12...)) then

or

if Var = {1; 5; 12...} then

I'm sure there is something like that and the answer will be obvious, but I can't find it. I specify that this is VBA for Access.

Configuration: Windows XP / Firefox 8.0.1

10 answers

telliak Posted messages 3652 Registration date   Status Member Last intervention   885
 
Hi,
Have you tried something like
Select Case Var Case 1, 5, 12, ... Instructions Case else End select
?
it's hard to make it simpler than that.
1
Patrice33740 Posted messages 8400 Registration date   Status Member Last intervention   1 783
 
Well seen, exactly :
Sub tst() Dim var As Integer var = 12 Select Case var Case 8, 9, 10, 11, 12, 13, 14, 15 MsgBox var & " exists" Case Else MsgBox var & " unknown" End Select End Sub
0
panda
 
plain and simple!
it's easy, all you had to do was think of it!
0