Solved

IF...Statement with (n) number of OR's

Posted on 2007-04-10
5
143 Views
Last Modified: 2013-11-25
I need to create an If...Else...Statement where there is going to be multiple 'OR's and I need help on the best way to do this.

Here is my If...Statement where I only have one 'OR'.

If sSFPRNumber = "7185" Or sSFPRNumber = "7481" Then
            nOutsideProvider = 0
 Else
            nOutsideProvider = 1
 End If

I now have all of the numbers in an array and I would like to loop through the array to create the above IF...Statement.
What is the best way to accomplish this?
0
Comment
Question by:huerita37
  • 3
  • 2
5 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 18885665
if you have the numbers in an "array" then you can not dynamically create programming constructs (ie if statements)

you could try creating a dictionary object and then checking if the value exists in the list.

If you reference microsoft scripting runtime and do

Dim x as new dictionary

x.add 7185, 0 'the second number is the value returned if this number is the check
x.add 7481, 0

if x.exists(sSFPRNumber) then
     nOutsideProvider = x(sSFPRNumber)
else
    nOutsideProvider = 1
end if
0
 

Author Comment

by:huerita37
ID: 18885727
do I need to say    nOutsideProvider = x(sSFPRNumber)

couldn't I just use    nOutsideProvider = 0
0
 
LVL 35

Accepted Solution

by:
Raynard7 earned 500 total points
ID: 18885763
yes - you could, however I was not sure if you wanted different values associated with different items in your array - in which case you would set them when defining your dictionary, otherwise an exists would be sufficient,

similarly without using a dictionary you could just do a foreach in the array - then if the value sSFPR.... = the value pulled from the array then return 0 and exit the loop, otherwise if you get to the end of the loop with no matches return 1
0
 

Author Comment

by:huerita37
ID: 18885786
I was going to use the For...Each but this is nested in another For.. loop and I was trying to get away from looping so many times.

I am going to give this a try.  Thanks.  
0
 

Author Comment

by:huerita37
ID: 18886111
Can you have a multi-dimensional dictionary object?

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Window placement 17 65
Run code from text file in vb 1 32
Access query that references subform 5 35
message box in access 4 33
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now