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

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.