Solved

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

Posted on 2007-04-10
5
144 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

861 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

24 Experts available now in Live!

Get 1:1 Help Now