Solved

if digit is 1 Or 4 Or 7 Or 0

Posted on 2011-02-10
17
232 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:Shawn
  • 6
  • 5
  • 4
  • +1
17 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 34867445
If intRDigit = 1 Or intRDigit = 4 Or intRDigit = 7 Or intRDigit = 0 Then
strtest = "A"
ElseIf intRDigit = 2 Or intRDigit = 5 Or intRDigit = 8 Then
strtest = "B"
Else
strtest = "C"
End If
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34867455
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

0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 34867459
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
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34867465
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

0
 
LVL 1

Author Closing Comment

by:Shawn
ID: 34867498
brilliant. thank you for the choice :)

Shawn
0
 
LVL 75
ID: 34867504
One Line:

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

mx
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34867545
@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)
0
 
LVL 1

Author Comment

by:Shawn
ID: 34867565
i actually used the select case.
the digits are 0-9. the else covers 3, 6 and 9.
0
 
LVL 1

Author Comment

by:Shawn
ID: 34867575
the actual strings are quite bit longer than strtest = "A".
0
 
LVL 75
ID: 34867578
"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
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 34867593
> i actually used the select case.
So then why wasn't there at least a split?  I posted the select case option...
0
 
LVL 75
ID: 34867597
"Either does your Accepted solution  - so what?"
Never mind ... I see that it does.  
0
 
LVL 75
ID: 34867603
" I posted the select case option..."
Exactly ... First at that ...

mx
0
 
LVL 75
ID: 34867615
Still one line ... covering any number > 8:

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

mx
0
 
LVL 1

Author Comment

by:Shawn
ID: 34867650
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.
0
 
LVL 75
ID: 34867667
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
0
 
LVL 1

Author Comment

by:Shawn
ID: 34867676
good point. thx :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question