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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To do a select case using two variables or parameters

Status
Not open for further replies.

cesark

Programmer
Dec 20, 2003
621
Hi!

Is it possible to do a select case with VB.NET using two variables or parameters? For example, something like this:
Code:
Dim family As integer = familyProduct.SelectedItem.Value
Dim prod As integer = product.SelectedItem.Value

Select Case (family and prod)
Case 1 and 22
 Response.Redirect("anotherPage.aspx")

Case 2 and 29
 Response.Redirect("anotherPage2.aspx")

Case 3 and 36
 Response.Redirect("anotherPage3.aspx")
...

End Select
..But this code doesn' t work.

Thanks,
Cesar
 
just use an if statement.

if family = 1 and prod = 22 then

elseif family = 2 and prod = 29

elseif....

else...
 
how about
Code:
Select Case i_input
   Case 0, 10
      Console.WriteLine("input is 0 or 10")
   Case 12, 15
      Console.WriteLine("input is 12 or 15")
   Case Else
      Console.WriteLine("case not met")
End Select
hth,
Marty
 
Ok thanks, it works. But, Is it not possible with 'Select Case'?
 
No, cappmgr. I need the cases like:
Code:
case (family = 1) and (prod = 22) [I]'Family selection to 1 and product selection to 22[/I]

case (family = 2) and (prod = 35)
case (family = 3) and (prod = 42)
...

 
sorry about that
Code:
Select Case True
    Case (i_input1 = 1 And i_input2 = 22) 
        	Console.WriteLine("input is 1 and 22")	
    Case (i_input1 = 2 And i_input2 = 29) 
	        Console.WriteLine("input is 2 and 29")	
    Case Else
        	Console.WriteLine("case not met")
End Select
Marty
 
Yes! It works fine. Thank you :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top