Solved

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…

809 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