Forums
This topic is locked
more efficient way
Posted 09 Mar 2005 20:49:37
1
has voted
09 Mar 2005 20:49:37 adam partridge posted:
whats a more efficient way of writing this :<%If Recordset1.Fields.Item("stravrvalue".Value < 3 Then%>
<div class="smileyBad"><strong><%= FormatNumber((Recordset1.Fields.Item("stravrvalue".Value), 2, -2, -2, -2) %></strong> avg score</div>
<%End If%>
<%If Recordset1.Fields.Item("stravrvalue".Value > 3 AND Recordset1.Fields.Item("stravrvalue".Value < 6 Then%>
<div class="smileyOk"><strong><%= FormatNumber((Recordset1.Fields.Item("stravrvalue".Value), 2, -2, -2, -2) %></strong> avg score</div>
<%End If%>
<%If Recordset1.Fields.Item("stravrvalue".Value > 6 Then%>
<div class="smileyGood"><strong><%= FormatNumber((Recordset1.Fields.Item("stravrvalue".Value), 2, -2, -2, -2) %></strong> avg score</div>
<%End If%>
<%If isnull(Recordset1.Fields.Item("stravrvalue".Value) Then%>
no votes as of yet
<%End If%>
any suggestions seems a bit long winded
Replies
Replied 09 Mar 2005 20:57:47
09 Mar 2005 20:57:47 Chris Charlton replied:
I'd use <i>switch case</i> statement (check value) to assign a variable for the your CSS <i>class</i>. Then an <i>If...else</i> statement to check if null or not (then outputs div w/class var).
~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>
~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>
Replied 10 Mar 2005 11:11:26
10 Mar 2005 11:11:26 Lee Diggins replied:
Hi Adam
Chris' idea is a good one on this, if you need help post back.
Just looking through your IF statements, this logic won't actually match a score of 3. You've got < 3, > 3 & < 6 and > 6.
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Chris' idea is a good one on this, if you need help post back.
Just looking through your IF statements, this logic won't actually match a score of 3. You've got < 3, > 3 & < 6 and > 6.
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 10 Mar 2005 17:26:17
10 Mar 2005 17:26:17 adam partridge replied:
lee thanks i hadnt spotted that !
im not entirely sure what chris means about using the switch case statement
could someone please elaborate
im not entirely sure what chris means about using the switch case statement
could someone please elaborate
Replied 10 Mar 2005 20:18:53
10 Mar 2005 20:18:53 Simon Martin replied:
Hi Adam,
CASE statements are like IF ELSE statements, only they let you have many options i.e. not just A or B
www.codefixer.com/tutorials/select_case.asp gives you a clear example of how to use them.
Live the life you love
Love the life you live
~ ~ ~ ~ ~ ~ ~
<b>Simon Martin</b> - <i>DMXzone Manager</i>
<font size=1>[ Dreamweaver MX/MX2004 | ASP | SQL | XHTML/CSS | Web Accessibility ] </font id=size1>
CASE statements are like IF ELSE statements, only they let you have many options i.e. not just A or B
www.codefixer.com/tutorials/select_case.asp gives you a clear example of how to use them.
Live the life you love
Love the life you live
~ ~ ~ ~ ~ ~ ~
<b>Simon Martin</b> - <i>DMXzone Manager</i>
<font size=1>[ Dreamweaver MX/MX2004 | ASP | SQL | XHTML/CSS | Web Accessibility ] </font id=size1>
Replied 10 Mar 2005 20:20:13
10 Mar 2005 20:20:13 Chris Charlton replied:
Here's one link I Google'd up: www.developersdex.com/asp/message.asp?p=2978&r=3870084 (anyone got a better link?).
It's basically a shorthand to writing a lot of <i>If...Else</i> statements, so you could just write a few <i>If...Else</i>'s to do the same thing.
~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>
It's basically a shorthand to writing a lot of <i>If...Else</i> statements, so you could just write a few <i>If...Else</i>'s to do the same thing.
~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>
Replied 11 Mar 2005 12:00:11
11 Mar 2005 12:00:11 Simon Martin replied:
I like the results of my googling more
Live the life you love
Love the life you live
~ ~ ~ ~ ~ ~ ~
<b>Simon Martin</b> - <i>DMXzone Manager</i>
<font size=1>[ Dreamweaver MX/MX2004 | ASP | SQL | XHTML/CSS | Web Accessibility ] </font id=size1>
Live the life you love
Love the life you live
~ ~ ~ ~ ~ ~ ~
<b>Simon Martin</b> - <i>DMXzone Manager</i>
<font size=1>[ Dreamweaver MX/MX2004 | ASP | SQL | XHTML/CSS | Web Accessibility ] </font id=size1>
Replied 11 Mar 2005 13:26:17
11 Mar 2005 13:26:17 Lee Diggins replied:
Hi Adam
I've put this bit of test code together for you to play with, hopefully it'll give you an insight into using the select case. Not guaranteeing it'll work for you straight away as you'll have to tweak it, maybe.
Post back with any questions you may have:
Dim strOut, strOK, myTest
myTest = Recordset1.Fields.Item("stravrvalue".Value
If IsNull(myTest) Then
strOut = ("no votes as of yet"
strOK = 0
Else
' Select case statements do not allow the use of < > etc,
' but you define and range of numbers like the example below.
' If you need to check for a greater than value then you have
' to revert to an IF statement to resolve this.
strOK = 1
Select Case myTest
Case 1, 2, 3
strOut = "smileyBad"
Case 4, 5, 6
strOut = "smileyOk"
Case Else
If myTest > 6 Then
strOut = "smileyGood"
End If
End Select
End If
If strOK = 1 Then
Response.Write("<div class="""strOut"""><strong>" & FormatNumber((Recordset1.Fields.Item("stravrvalue".Value), 2, -2, -2, -2) & "</strong> avg score</div>"
Else
Response.Write(strOut)
End If
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Edited by - Digga the Wolf on 11 Mar 2005 13:30:04
I've put this bit of test code together for you to play with, hopefully it'll give you an insight into using the select case. Not guaranteeing it'll work for you straight away as you'll have to tweak it, maybe.
Post back with any questions you may have:
Dim strOut, strOK, myTest
myTest = Recordset1.Fields.Item("stravrvalue".Value
If IsNull(myTest) Then
strOut = ("no votes as of yet"
strOK = 0
Else
' Select case statements do not allow the use of < > etc,
' but you define and range of numbers like the example below.
' If you need to check for a greater than value then you have
' to revert to an IF statement to resolve this.
strOK = 1
Select Case myTest
Case 1, 2, 3
strOut = "smileyBad"
Case 4, 5, 6
strOut = "smileyOk"
Case Else
If myTest > 6 Then
strOut = "smileyGood"
End If
End Select
End If
If strOK = 1 Then
Response.Write("<div class="""strOut"""><strong>" & FormatNumber((Recordset1.Fields.Item("stravrvalue".Value), 2, -2, -2, -2) & "</strong> avg score</div>"
Else
Response.Write(strOut)
End If
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Edited by - Digga the Wolf on 11 Mar 2005 13:30:04