Results 1 to 14 of 14

Thread: A Select Case problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Barcelona
    Posts
    70

    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

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    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:
    1. If userclass <> 0 then
    2.    Select Case election1.selecteditem.value
    3.       Case 1
    4.          Response.Redirect("new_user2B.aspx")
    5.       'etc....
    6.    End Select
    7. Else
    8.    Response.Redirect("new_user2A.aspx")
    9. End If

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Barcelona
    Posts
    70
    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

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  7. #7
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    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.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Barcelona
    Posts
    70
    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

  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Barcelona
    Posts
    70
    Ok, thank you very much !

  11. #11
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    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.

  12. #12
    Addicted Member
    Join Date
    Apr 2003
    Posts
    170
    i wonder why no one used
    "Case Else:"

  13. #13
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  14. #14
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    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
  •  



Click Here to Expand Forum to Full Width