Link to home
Start Free TrialLog in
Avatar of Shawn
ShawnFlag for Canada

asked on

if digit is 1 Or 4 Or 7 Or 0

I am trying the query below but it doesn't work. Can't remember how to do this.

something like this??
If intRDigit = In(1,4,7,0) Then

If intRDigit = 1 Or 4 Or 7 Or 0 Then
strtest = "A"
ElseIf intRDigit = 2 Or 5 Or 8 Then
strtest = "B"
Else
strtest = "C"
End If
ASKER CERTIFIED SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can also use this

If InStr(intRDigit, "1470") > 0 Then
    strtest = "A"
ElseIf InStr(intRDigit, "258") > 0 Then
    strtest = "B"
Else
    strtest = "C"
End If

Open in new window

Or you could use Select Case -

SELECT CASE IntRDigit
   Case 1,4,7,0
      strtest = "A"
   Case 2, 5, 8
      strtest = "B"
   Case Else
      strtest = "C"
End Select
Or use SELECT CASE

Select Case intRDigit
Case 1, 4, 7, 0
    strtest = "A"
Case 2, 5, 8
    strtest = "B"
Case Else
    strtest = "C"
End Select

Open in new window

Avatar of Shawn

ASKER

brilliant. thank you for the choice :)

Shawn
One Line:

strtest = Choose(strtest + 1, "A", "A", "B", "C", "A", "B", "C", "A", "B")

mx
@Dbmx

This is both shorter, and correct, as long as intRDigit is >= 0
Your Choose options don't cover more than 0-8.

strtest = Left(Mid("AABCABCAB", intRDigit + 1, 1) + "C", 1)
Avatar of Shawn

ASKER

i actually used the select case.
the digits are 0-9. the else covers 3, 6 and 9.
Avatar of Shawn

ASKER

the actual strings are quite bit longer than strtest = "A".
"Your Choose options don't cover more than 0-8."
Either does your Accepted solution  - so what?

And your new solution uses two functions instead of 1 !

mx
> i actually used the select case.
So then why wasn't there at least a split?  I posted the select case option...
"Either does your Accepted solution  - so what?"
Never mind ... I see that it does.  
" I posted the select case option..."
Exactly ... First at that ...

mx
Still one line ... covering any number > 8:

strtest = Nz(Choose(strtest + 1, "A", "A", "B", "C", "A", "B", "C", "A", "B"), "C")

mx
Avatar of Shawn

ASKER

leew
>>So then why wasn't there at least a split?
originally I just tested them and gave out the points to the first correct answer.
afterwards I decided which one to use. sorry about that. If you really want I can see if I can't reopen to distribute the points.
Just a suggestion ... sometimes it's best to wait for a few posts, especially when it's clear there will be many possible solutions, some simpler than others :-)

mx
Avatar of Shawn

ASKER

good point. thx :)