|
-
Feb 6th, 2004, 09:12 AM
#1
Thread Starter
Lively Member
A Select Case problem
Hi !
What is wrong from the second 'case' to the end? (I know that is wrong, but I want to know how can I do it)
For example; the second 'Case' should be: If the case is different to “0” and ‘election1.SelectedItem.Value = 1’ ...
Code:
Call whatPage (userClass)
End Sub
Sub whatPage (userClass As integer)
Select Case userClass
Case “0”
Response.Redirect("new_user2A.aspx")
Case "<>0", election1.SelectedItem.Value = 1
Response.Redirect("new_user2B.aspx")
Case "<>0", election1.SelectedItem.Value = 2
Response.Redirect("new_user2C.aspx")
Case "<>0", election1.SelectedItem.Value = 3
Response.Redirect("new_user2D.aspx")
Case "<>0", election1.SelectedItem.Value = 4
Response.Redirect("new_user2E.aspx")
........
Thanks
-
Feb 6th, 2004, 09:39 AM
#2
Frenzied Member
I don't know that you can test a case with AND, at least in that way. The comma separator is an OR type separator. Your second case tests for "0" OR election1.selecteditem.value.
Also, it appears that userclass is an integer. "0", "<>0" are strings, or at least a char.
Try:
VB Code:
If userclass <> 0 then
Select Case election1.selecteditem.value
Case 1
Response.Redirect("new_user2B.aspx")
'etc....
End Select
Else
Response.Redirect("new_user2A.aspx")
End If
-
Feb 6th, 2004, 09:46 AM
#3
PowerPoster
Hi,
First of all remove all the quotation marks. UserClass is an integer not a string!!
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 6th, 2004, 10:19 AM
#4
PowerPoster
Hi Salvelinus,
"I don't know that you can test a case with AND"
Try
Dim iTest As Integer
iTest = 3
Select Case True
Case iTest > 0 And iTest < 5
txt1.Text = "It Works"
End Select
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 6th, 2004, 10:33 AM
#5
Thread Starter
Lively Member
Perfect ! salvelinus, now runs fine.
In fact, what is the main difference between using (If..Then), (If..Then..Elseif) or (Select Case)?
As I read it, I understand that if I have more than two conditions I have to use (Elseif) or (Select Case), but in that case it is better (Select Case).
And why it isn't equal to use five conditions in five blocks of (If..Then..End If) than in one block of (Elseif) or in one block of (Select Case)?
Thank you,
Cesar
-
Feb 6th, 2004, 11:15 AM
#6
PowerPoster
HI,
"And why it isn't equal to use five conditions in five blocks of (If..Then..End If) than in one block of (Elseif) or in one block of (Select Case)?"
If you use one block, the code exits the block once a match is found and the code therin executed.
If you use five different condition checks outside of a block, the code will test all conditions whether or not a match is found.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 6th, 2004, 11:46 AM
#7
Frenzied Member
Originally posted by taxes
Hi Salvelinus,
"I don't know that you can test a case with AND"
Try
Dim iTest As Integer
iTest = 3
Select Case True
Case iTest > 0 And iTest < 5
txt1.Text = "It Works"
End Select
Hi yourself. I didn't mean the actual AND keyword. I worded my post poorly. I meant the way it was set up originally. I capitalized AND just to make it stand out. My bad.
-
Feb 6th, 2004, 12:30 PM
#8
Thread Starter
Lively Member
Good ! taxes
Do you think that the follow structure is the best 'Control Structure' choice in this case?:
Code:
If IdUser = 0 Then
message1.text = "something"
End If
If idUser <> 0 Then
If classUs.SelectedItem.Value = 1 Then
Response.Redirect("somepage1.aspx")
End If
If classUs.SelectedItem.Value = 2 Then
Response.Redirect("somepage2.aspx")
End If
End If
Cesar
-
Feb 6th, 2004, 07:00 PM
#9
PowerPoster
Hi,
No!
Try
If IdUser = 0 Then
message1.text = "something"
Else
Select Case classUs.SelectedItem.Value
case 1
Response.Redirect("somepage1.aspx")
case 2
Response.Redirect("somepage2.aspx")
case .......
End Select
End If
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 7th, 2004, 04:52 AM
#10
Thread Starter
Lively Member
Ok, thank you very much !
-
Feb 7th, 2004, 05:57 AM
#11
Frenzied Member
Taxes method & mine are the same, except we reversed which value is checked first in the If statement.
To decide which value, 0 or <> 0, to check first, check the one that's most common first. That way you'll make fewer unnecessary checks.
-
Feb 7th, 2004, 03:37 PM
#12
Addicted Member
i wonder why no one used
"Case Else:"
-
Feb 7th, 2004, 04:18 PM
#13
PowerPoster
Hi ZaidGS,
"i wonder why no one used
"Case Else:"
Try it and see what problems you create!!!! It is just not applicable to the requirements stated.
It would be far too cumbersome as you would have to test multiple conditions on most lines and you would have the difficulty of deciding how to treat the difference between 0 and any other number when classUs.SelectedItem.Value exceeds the range of values which need to be checked and .......... Hell, I could list a dozen problems you would have!!
Last edited by taxes; Feb 7th, 2004 at 09:37 PM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 7th, 2004, 09:04 PM
#14
Frenzied Member
As my daughter Megan pointed out Else would run every time that <> zero.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|