Case statement - Programmers Heaven

#### Howdy, Stranger!

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

# Case statement

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
Else
Msgbox "blah"
End If

• 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
: 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]

• 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
: Else
: Msgbox "blah"
: End If
:
[code]
Select Case intAge
Case Is < 0
Msgbox "error, younger than 0"
Case 0 To 30