Solved

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

Posted on 2007-04-10
5
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

631 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