Can anyone help mes , I am comparing a value using CASE statement in VB.net , but need to have a range of values in easch CASE
I want to say do someting if Value to compare is "greater than 75 and
less than 90"
Here is my code, any help is very much appreciated, thanks
Select Case intResult
Case Is >= 75 ' should say greater than or equeal to 75 AND less than 90
e.Row.Cells(1).BackColor = Drawing.Color.Gold
Case Is < 65
e.Row.Cells(1).BackColor = Drawing.Color.Red
Case Else
e.Row.Cells(1).BackColor = Drawing.Color.White
End Select
With Line numbers ....
Select Case intResult
'(greater than or equeal to 75) AND (less than 90)
Case Is >= 75 AND Case Is <90
e.Row.Cells(1).BackColor = Drawing.Color.Gold
Case Is < 65
e.Row.Cells(1).BackColor = Drawing.Color.Red
Case Else
e.Row.Cells(1).BackColor = Drawing.Color.White
End Select
Normally, you would use the "To" keyword to see if a value is between two whole values, but some possible values get lost if you use Doubles or Singles.
Since you are using an integer, you can use the "To" keyword, but you need to rework your logic, i.e.:
Select Case intResult
' greater than or equal to 75 and less than 90
Case 75 To 89
' To is inclusive. 89 is the first int less than 90
'...code
End Select
If this were using floating point values (double/single) you could build your select statement backwards, from lowest possible values to highest values:
Select Case intResult
Case Is < 65.0
' code for anything less than 65
Case Is < 75
' code for anything less than 75
' since VB cases do not drop through like C++,
' call a method to execute similar code, since
' this case would fall under your 'Else' clause in
' your posted code.
Call ProcessElseValue(intResult)
Case Is < 90.0
'...code that executes if less than 90
' this is the same as a case statement that is >= 75, but < 90
Case Else' See case Is < 75 above
Call ProcessElseValue(intResult)
End Select
---------------------------------------
MCP - Web Based Client Development .NET 2.0
Marked as answer by aidoco on Mar 16, 2007 03:51 PM
aidoco
Member
379 Points
96 Posts
VB.net CASE SELECT Statement , how to include AND && OR || in a CASE
Mar 13, 2007 03:55 PM|LINK
Hi
Can anyone help mes , I am comparing a value using CASE statement in VB.net , but need to have a range of values in easch CASE
I want to say do someting if Value to compare is "greater than 75 and less than 90"
Here is my code, any help is very much appreciated, thanks
Select Case intResult
Case Is >= 75 ' should say greater than or equeal to 75 AND less than 90
e.Row.Cells(1).BackColor = Drawing.Color.Gold
Case Is < 65
e.Row.Cells(1).BackColor = Drawing.Color.Red
Case Else
e.Row.Cells(1).BackColor = Drawing.Color.White
End Select
With Line numbers ....Select Case intResult '(greater than or equeal to 75) AND (less than 90) Case Is >= 75 AND Case Is <90 e.Row.Cells(1).BackColor = Drawing.Color.Gold Case Is < 65 e.Row.Cells(1).BackColor = Drawing.Color.Red Case Else e.Row.Cells(1).BackColor = Drawing.Color.White End SelectASP.NET <%@ Page Language="VB" %> vbscript Web Forms visual studio visual web developer express vwd express .net Asp .net
loydall
Participant
975 Points
366 Posts
Re: VB.net CASE SELECT Statement , how to include AND && OR || in a CASE
Mar 13, 2007 05:05 PM|LINK
or
Case
Is >= 75 And intResult < 90loydall
Participant
975 Points
366 Posts
Re: VB.net CASE SELECT Statement , how to include AND && OR || in a CASE
Mar 13, 2007 05:06 PM|LINK
ps2goat
Star
10845 Points
1977 Posts
Re: VB.net CASE SELECT Statement , how to include AND && OR || in a CASE
Mar 13, 2007 05:16 PM|LINK
If this were using floating point values (double/single) you could build your select statement backwards, from lowest possible values to highest values:
MCP - Web Based Client Development .NET 2.0
aidoco
Member
379 Points
96 Posts
Re: VB.net CASE SELECT Statement , how to include AND && OR || in a CASE
Mar 16, 2007 03:50 PM|LINK
Thank you very much for your reply guys , much appreciated.
Thanks PS2goat