Shawn

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

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

membership

This solution is only available to members.

To access this solution, you must be a member of Experts Exchange.

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

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
```

ASKER

brilliant. thank you for the choice :)

Shawn

Shawn

One Line:

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

mx

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)

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)

ASKER

i actually used the select case.

the digits are 0-9. the else covers 3, 6 and 9.

the digits are 0-9. the else covers 3, 6 and 9.

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

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...

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.

Never mind ... I see that it does.

" I posted the select case option..."

Exactly ... First at that ...

mx

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

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

mx

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.

>>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

mx

ASKER

good point. thx :)

Open in new window