Dear All

I am getting confused with a select case statement and I would like some
help.

Dim Day1Max
Dim TargetLow
Dim TargetHigh

Day1Max = 55
TargetLow = 63
TargetHigh = 90


Select case Cint(Day1Max)
Case >= 1 and <= Cint(TargetLow)
Day1Graph = 1
Case Cint(Day1Max) >= Cint(TargetLow) and Cint(Day1Max) =<
Cint(TargetHigh)
Day1Graph = 2
Case Cint(Day1Max) > Cint(TargetHigh)
Day1Graph = 3
case else
Day1Graph = 4
End select

What I am testing is:

If Day1Max < 62 then Day1Graph = 1
If Day1Max >= 63 and <= 89 then Day1Graph = 2
If Day1Max >= 90 the Day1Graph = 3

I can't hard code the values because the variable values are returned from a
stored procedure and vary with each person.


This select statement always returns Day1Graph as 4. How would I change the
Select Case statement to work? Do I need to Cint the value?

Thanks...

Alastair MacFarlane

Re: Select Case Question: So Easy? by Larry

Larry
Sun Aug 31 15:13:16 CDT 2003

"Alastair MacFarlane" <amacfarlane@blueyonder.co.uk> wrote
>
> I am getting confused with a select case statement and I would like some
> help.

Why not just use If/Then statements?

LFS



Re: Select Case Question: So Easy? by Evertjan

Evertjan
Sun Aug 31 15:19:17 CDT 2003

Alastair MacFarlane wrote on 31 aug 2003 in
microsoft.public.scripting.vbscript:
> Select case Cint(Day1Max)
> Case >= 1 and <= Cint(TargetLow)
> Day1Graph = 1
> Case Cint(Day1Max) >= Cint(TargetLow) and Cint(Day1Max) =<
> Cint(TargetHigh)
> Day1Graph = 2
> Case Cint(Day1Max) > Cint(TargetHigh)
> Day1Graph = 3
> case else
> Day1Graph = 4
> End select

Case needs a list of values that match the select case value, so no > <=
etc.

But you could mock the idea:

DM = Cint(Day1Max)
Select Case True
Case (DM>=1) and (DM<=Cint(TargetLow))
Day1Graph = 1
Case (DM>=Cint(TargetLow)) and (DM=<Cint(TargetHigh))
Day1Graph = 2
Case DM>Cint(TargetHigh)
Day1Graph = 3
case else
Day1Graph = 4
End select

But then the whole idea of "select case" is gone, and you could do:

DM = Cint(Day1Max)
If (DM>=1) and (DM<=Cint(TargetLow)) Then
Day1Graph = 1
Elseif (DM>=Cint(TargetLow)) and (DM=<Cint (TargetHigh)) Then
Day1Graph = 2
Elseif DM>Cint(TargetHigh) Then
Day1Graph = 3
Else
Day1Graph = 4
End If

======================

btw: your selection is strange, because
if Cint(Day1Max)=0 then Day1Graph = 4
unless Cint(TargetLow)=0, then Day1Graph = 2
Is that the effect intended ?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Re: Select Case Question: So Easy? by c

c
Mon Sep 01 06:29:47 CDT 2003

Hi, Alastair,

> This select statement always returns Day1Graph as 4. How would I change the
> Select Case statement to work? Do I need to Cint the value?

I think this should do the trick; I think "Case Is" is what you were looking for.

' just a button to test the function
Private Sub Command1_Click()
If Day1Graph(0) <> 4 Then MsgBox "bad at 0"
If Day1Graph(1) <> 1 Then MsgBox "bad at 1"
If Day1Graph(63) <> 1 Then MsgBox "bad at 63"
If Day1Graph(64) <> 2 Then MsgBox "bad at 64"
If Day1Graph(90) <> 2 Then MsgBox "bad at 90"
If Day1Graph(91) <> 3 Then MsgBox "bad at 91"
End Sub

' the function itself; you can put the case statement
' anywhere, but this was all I knew, so I just made
' it its own function
Private Function Day1Graph(Day1Max As Integer) As Integer
Const TargetLow = 63
Const TargetHigh = 90

Select Case CInt(Day1Max)
Case Is < 1: Day1Graph = 4
Case Is <= CInt(TargetLow): Day1Graph = 1
Case Is <= CInt(TargetHigh): Day1Graph = 2
Case Else: Day1Graph = 3
End Select
End Function


Peace,
--Carl

Re: Select Case Question: So Easy? by Al

Al
Wed Sep 03 21:34:49 CDT 2003


"Alastair MacFarlane" <amacfarlane@blueyonder.co.uk> wrote in message
news:efTi2p$bDHA.1580@tk2msftngp13.phx.gbl...
> Dear All
>
> I am getting confused with a select case statement and I would like some
> help.

I am confused by the fact that your script below runs without error...

> Dim Day1Max
> Dim TargetLow
> Dim TargetHigh
>
> Day1Max = 55
> TargetLow = 63
> TargetHigh = 90
>
>
> Select case Cint(Day1Max)
> Case >= 1 and <= Cint(TargetLow)

The typical "case" statement is more like:

Case 1, 2, 7
msgbox "the value was either 1, 2, or 7"

Your case statement looks more like a boolean expression not being assigned
to a variable, i.e.:

( case >= 1 ) and ... what?

If you want to check to see if a value is in a range, then CASE does not do
it for you, as it is designed more to pick from a discrete set of
possibilities.

> Day1Graph = 1
> Case Cint(Day1Max) >= Cint(TargetLow) and Cint(Day1Max) =<
> Cint(TargetHigh)

Now, the above seems syntactically more complete and correct, but is the
same as:

case (boolean expression)

and will evaluate as either:

case true

or:

case false

neither of which appears likely because the select case is looking at an
integer of some sort.

/Al

> Day1Graph = 2
> Case Cint(Day1Max) > Cint(TargetHigh)
> Day1Graph = 3
> case else
> Day1Graph = 4
> End select
>
> What I am testing is:
>
> If Day1Max < 62 then Day1Graph = 1
> If Day1Max >= 63 and <= 89 then Day1Graph = 2
> If Day1Max >= 90 the Day1Graph = 3
>
> I can't hard code the values because the variable values are returned from
a
> stored procedure and vary with each person.
>
>
> This select statement always returns Day1Graph as 4. How would I change
the
> Select Case statement to work? Do I need to Cint the value?
>
> Thanks...
>
> Alastair MacFarlane
>
>
>