Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Long condition question

Status
Not open for further replies.

sonya9879

Programmer
Jun 18, 2004
147
CA
Hi, I have a piece of code that looks like this:

Select Case ID
Case 1
var1 = "something"
var2 = "something"
var3 = "something"
Case 2
var1 = "somethingelse"
var2 = "somethingelse"
var3 = "somethingelse"
Case 3
var1 = "somethingddd"
var2 = "somethingddd"
var3 = "somethingddd"
End Select

Its a very simple case statement as you can see. Now the problem now is that the ID will go to 1000, and therefore I need to do a lot of case 4, case 5, case 6, etc..
Does anyone have some idea what alternative I have to this? I know I could use IF conditions but its the same thing, it must be a different way than typing a long script with 1000 lines of conditional code.
Any idea will be appreciated thanks
 
Are there any relationships between the Var[1/2/3] values and the ID value? Also, is this SQL code or VB/ASP?

If VB/ASP code, you could construct an array that contains each of the three VAR values, and the ID is a pointer to the appropriate elements in the array. This of course assumes that the VAR/ID values don't change after compiled....

"I swear by my life and my love of it that I will never live for the sake of another man, nor ask another man to live for mine."
— John Galt
Atlas Shrugged

If you want to get the best response to a question, please check out FAQ222-2244 first

 
As HRoarke points out, it will be fairly easy if there is some relationship as you could do something like
:
Code:
        Select Case ID
            Case 1 To 10
                 var1 = "something"
                 var2 = "something"
                 var3 = "something"
            Case 11 To 20
                 var1 = "somethingelse"
                 var2 = "somethingelse"
                 var3 = "somethingelse"
            Case 21, 23, 25
                 var1 = "somethingddd"
                 var2 = "somethingddd"
                 var3 = "somethingddd"
            Case Else
                 var1 = "somethingeee"
                 var2 = "somethingeee"
                 var3 = "somethingeee"
        End Select
If every different combination, has a different outcome then something like a lookup table may be more suitable (that could be a lookup table in a database or a DataTable).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
thanks guys for both answers. this is VB.NET and I didnt know that u could use Case 1 To 100, thats great. There is no relation between ID and the Var[1/2/3] but i have plenty of IDs that will use the same Var[1/2/3] result. Therefore I think that the Case 1 to 100 will just do what I am trying to achieve here with a few lines of code then. Thanks to both of you for your help guys
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top