Case statement - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Case statement

osooso Posts: 1Member
i know i can use a case statement for this code but i dont know how to make the code for it... can anyone help?

If(intAge<0) Then
Msgbox "error, younger than 0"
ElseIf (intAge>100) Then
Msgbox "error, over 100"
ElseIf (intAge<=30) then
Msgbox "in your prime"
Else
Msgbox "blah"
End If

Comments

  • sumedhsumedh Posts: 103Member
    : i know i can use a case statement for this code but i dont know how to make the code for it... can anyone help?
    :
    : If(intAge<0) Then
    : Msgbox "error, younger than 0"
    : ElseIf (intAge>100) Then
    : Msgbox "error, over 100"
    : ElseIf (intAge<=30) then
    : Msgbox "in your prime"
    : Else
    : Msgbox "blah"
    : End If
    :

    'select-case' can only be used if the variable can only have constant values and not ones which lie within a certain range, like u have here......

    [code]
    select case intAge
    case 1: 'do something
    case 2: 'some more
    end select
    [/code]

    the above code does'nt solve ur purpose though.......

    in such a case, what u've done is perfect, using the 'if-then-elseif' loop...

    -sumedh
    [hr]
    [purple]
    [b]Dont think you can, [red]KNOW[/red] you can....
    [/b]
    [purple]

  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : i know i can use a case statement for this code but i dont know how to make the code for it... can anyone help?
    :
    : If(intAge<0) Then
    : Msgbox "error, younger than 0"
    : ElseIf (intAge>100) Then
    : Msgbox "error, over 100"
    : ElseIf (intAge<=30) then
    : Msgbox "in your prime"
    : Else
    : Msgbox "blah"
    : End If
    :
    [code]
    Select Case intAge
    Case Is < 0
    Msgbox "error, younger than 0"
    Case 0 To 30
    Msgbox "in your prime"
    Case Is > 100
    Msgbox "error, over 100"
    Case Else
    Msgbox "blah"
    End Select
    [/code]
Sign In or Register to comment.