Connecting Tech Pros Worldwide Forums | Help | Site Map

Syntax For Using A Variable To Evaluate Multiple "Or" Conditions

Sheldon
Guest
 
Posts: n/a
#1: Dec 14 '06
In the code below, it seems like there should be a way to simplify the
expression to search for the specific values of 1, 9, 10, 11 and 12.
It would be more tedious if I was looking to execute some code when x
would evaluate to, say, 1 or 3 or 5 or 7 and so on. Could someone
provide a suggestion?
.........
Dim x As Boolean
x = (Val(Left(Format(Date, "mm/dd/yyyy"), 2)) >= 9) Or
(Val(Left(Format(Date, "mm/dd/yyyy"), 2)) < 2)
..........
Thanks,
Sheldon Potolsky




Larry Linson
Guest
 
Posts: n/a
#2: Dec 14 '06

re: Syntax For Using A Variable To Evaluate Multiple "Or" Conditions



"Sheldon" <SHPsalm139@aol.comwrote in message
news:1166042512.223264.299600@l12g2000cwl.googlegr oups.com...
Quote:
In the code below, it seems like there should be a way to simplify the
expression to search for the specific values of 1, 9, 10, 11 and 12.
It would be more tedious if I was looking to execute some code when x
would evaluate to, say, 1 or 3 or 5 or 7 and so on. Could someone
provide a suggestion?
........
Dim x As Boolean
x = (Val(Left(Format(Date, "mm/dd/yyyy"), 2)) >= 9) Or
(Val(Left(Format(Date, "mm/dd/yyyy"), 2)) < 2)
This should work, if you like it any better:

Select Case Val(Left(Format(Date, "mm/dd/yyyy"), 2)
Case 1, 9, 11, 12
... do something
Case Else
... do something else
End Select

Larry Linson
Microsoft Access MVP


Marshall Barton
Guest
 
Posts: n/a
#3: Dec 14 '06

re: Syntax For Using A Variable To Evaluate Multiple "Or" Conditions


Sheldon wrote:
Quote:
>In the code below, it seems like there should be a way to simplify the
>expression to search for the specific values of 1, 9, 10, 11 and 12.
>It would be more tedious if I was looking to execute some code when x
>would evaluate to, say, 1 or 3 or 5 or 7 and so on. Could someone
>provide a suggestion?
>........
>Dim x As Boolean
>x = (Val(Left(Format(Date, "mm/dd/yyyy"), 2)) >= 9) Or
>(Val(Left(Format(Date, "mm/dd/yyyy"), 2)) < 2)

Select Case Month(Date)
Case 1, 9 To 12
. . .
Case Else
. . .
End Select

--
Marsh
Closed Thread