Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: Select case

  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts

    Select case

    total = 15.5 but it doesnt match any of the conditions
    Code:
    select case  total 
    case total < 50
    band = "fldBand1"
    case total <100 and  total >=50
    band = "fldBand2"
    case total >= 100
    band = "fldBand3"
    end select

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Silly question, but are you sure it's being stored as a number?

    Try a
    case "15.5" (with quotes) to see if it's treating it as text.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder
    Join Date
    Jun 2003
    Location
    Silicon Forest
    Posts
    155
    Thanks
    0
    Thanked 5 Times in 5 Posts
    This should be the correct syntax. Valid in VB so it should translate over nicely into ASP. Assuming that it is not a string as Nikki suggested.

    Code:
    Select Case total
        Case Is >= 100
          band = "fldBand3"
       Case 50 To 100
          band = "fldBand2"
       Case Is < 50
          band = "fldBand1"
    End Select
    They are reordered because that 100 was a problem. The 100 will be picked up by the first case and not the second.
    Last edited by CrzySdrs; 09-06-2005 at 06:38 PM.
    Whats the point of a signature?

  • #4
    Regular Coder
    Join Date
    Sep 2004
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Throw a Cint around total and see what happens

  • #5
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    tried that and it didnt work, ended up doing a load of ifs :s

  • #6
    Regular Coder
    Join Date
    Sep 2004
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, did some reading. With select case, it has to match, you can't do a range unless you do something like this:
    Code:
    Select Case myNumber
    Case 0,1,2,3,4,5
    ...
    Case 6,7,8,9,10
    ...
    Case Else
    ...
    End Select
    Which obviously won't work for what you are trying to do, so unforunately, the best solution is the one you have (if..else).

  • #7
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    *smacks self on head*
    Good to know. Thanks for posting that.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •