Forums

This topic is locked

Conditional Colour Change

Posted 18 Oct 2007 15:45:19
1
has voted
18 Oct 2007 15:45:19 Graham Hefford posted:
Hi

I have a calculation (see below) that if the result is less than the answer is in red, and if more than in white

<% Dim ShipL1Total %>
<% = Session("ShipTotals1" - Session("ShipTarget1" %>

<%if (ShipL1Total > Session("ShipTarget1") then
Response.Write("<font color=#003e80>(ShipL1Total)</font>"
ELSE
Response.Write("<font color=#003e80>(ShipL1Total)</font>"
End If
%>

Can anyone help in getting this working

Thanks

Replies

Replied 18 Oct 2007 16:28:23
18 Oct 2007 16:28:23 Georgi Kralev replied:
Hi Graham,

Try the following code:
<i><b>&lt;%</b>
Dim ShipL1Total
ShipL1Total = Session("ShipTotals1" - Session("ShipTarget1"
<b>%&gt;</b>
<b>&lt;%</b>
if (ShipL1Total &gt; Session("ShipTarget1") then
Response.Write("&lt;font color=#003e80&gt;(" & ShipL1Total & "&lt;/font&gt;"
Else
Response.Write("&lt;font color=#FF0000&gt;(" & ShipL1Total & "&lt;/font&gt;"
End If
<b>%&gt;</b></i>

Georgi Kralev

----------------------------------
Support - www.DMXzone.com
Replied 18 Oct 2007 16:33:10
18 Oct 2007 16:33:10 Georgi Kralev replied:
Also, instead <b>font color</b> it could be used css styles.

For example:
Add the following styles to your page:
<i>&lt;style type="text/css"&gt;
&lt;!--
<b>.smallTotal {color: #FF0000}</b>
<b>.largeTotal {color: #003e80}</b>
--&gt;
&lt;/style&gt;</i>

And the font tag could be replaced with span tag.
For example:
<i>
&lt;%
If (ShipL1Total &gt; Session("ShipTarget1") then
Response.Write("<b>&lt;span class=""largeTotal""</b>&gt;(" & ShipL1Total & "&lt;/span&gt;"
Else
Response.Write("<b>&lt;span class=""smallTotal""</b>&gt;(" & ShipL1Total & "&lt;/span&gt;"
End If
%&gt;</i>

I hope that you will find this useful.

Regards,

Georgi Kralev

----------------------------------
Support - www.DMXzone.com
Replied 19 Oct 2007 15:20:29
19 Oct 2007 15:20:29 Graham Hefford replied:
Hi George

Thanks for the code, I have tryed this and the colour does not change it stays red

Regards
Replied 19 Oct 2007 15:46:52
19 Oct 2007 15:46:52 Georgi Kralev replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Hi George

Thanks for the code, I have tryed this and the colour does not change it stays red

Regards
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
The color of the text depend on your calculation.
Check the following statements:
<i>ShipL1Total = Session("ShipTotals1" - Session("ShipTarget1"</i>
and
<i>If (ShipL1Total &gt; Session("ShipTarget1") then</i>

If you want the color to change set value which satisfy the if condition
To do that check the following code:

&lt;%
<b>Session("ShipTotals1" = 1000
Session("ShipTarget1" = 400</b>
Dim ShipL1Total
ShipL1Total = Session("ShipTotals1" - Session("ShipTarget1"
%&gt;
&lt;%
if (ShipL1Total &gt; Session("ShipTarget1") then
Response.Write("&lt;font color=#003e80&gt;(" & ShipL1Total & "&lt;/font&gt;"
Else
Response.Write("&lt;font color=#FF0000&gt;(" & ShipL1Total & "&lt;/font&gt;"
End If
%&gt;

Regards,

Georgi Kralev

----------------------------------
Support - www.DMXzone.com
Replied 22 Oct 2007 18:32:24
22 Oct 2007 18:32:24 Graham Hefford replied:
George Thanks for your contiuning help... Heres the test code. The colours still not change.

&lt;%@LANGUAGE="VBSCRIPT"%&gt;
&lt;!--#include file="Connections/AS400Test1.asp" --&gt;
&lt;%
Dim DisplayBoard
Dim DisplayBoard_cmd
Dim DisplayBoard_numRows

Set DisplayBoard_cmd = Server.CreateObject ("ADODB.Command"
DisplayBoard_cmd.ActiveConnection = MM_AS400Test1_STRING
DisplayBoard_cmd.CommandText = "SELECT * FROM DTWMS.WMMB6"
DisplayBoard_cmd.Prepared = true

Set DisplayBoard = DisplayBoard_cmd.Execute
DisplayBoard_numRows = 0
%&gt;

&lt;style type="text/css"&gt;
&lt;!--
.smallTotal {color: #FF0000}
.largeTotal {color: #003e80}
--&gt;
&lt;/style&gt;

&lt;%

Session("ShipTotals1" = Abs((DisplayBoard.Fields.Item("MBSHX1".Value))

Session("ShipTotals2" = Abs((DisplayBoard.Fields.Item("MBSHX2".Value))

Session("ShipTarget1" = Abs((DisplayBoard.Fields.Item("MBSPX1".Value))

Session("ShipTarget2" = Abs((DisplayBoard.Fields.Item("MBSPX2".Value))

%&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;

&lt;% Dim ShipL1Total %&gt;
&lt;% ShipL1Total = Session("ShipTotals1" - Session("ShipTarget1" %&gt;
&lt;% Session("ShipTarget2" = ShipL1Total %&gt;
&lt;%
If (Session("ShipL1Total" &gt; Session("ShipTarget1") then
Response.Write("&lt;font color=#003e80&gt;(" & ShipL1Total & "&lt;/font&gt;"
Else
Response.Write("&lt;font color=#FF0000&gt;(" & ShipL1Total & "&lt;/font&gt;"
End If
%&gt;
&lt;%
DisplayBoard.Close()
Set DisplayBoard = Nothing
%&gt;

Any ideas....
Replied 23 Oct 2007 10:07:14
23 Oct 2007 10:07:14 Georgi Kralev replied:
Hi Graham,

As I mentioned before:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>The color of the text depend on your calculation<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Therefore, if the color is not right check your calculation or the values which you assign:

I my opinion your If statement is wrong.
This is because I do not see the following session variable to be initialized: <b>Session("ShipL1Total"</b>

Therefore it have to look like this:

If (<b>ShipL1Total</b> &gt; Session("ShipTarget1") then

OR

If (<b>Session("ShipTarget2"</b> &gt; Session("ShipTarget1") then

(Because of the following statement: Session("ShipTarget2" = ShipL1Total)

Regards,



Georgi Kralev

----------------------------------
Support - www.DMXzone.com
Replied 23 Oct 2007 12:30:01
23 Oct 2007 12:30:01 Graham Hefford replied:
George

I am very sorry about bothering you with this, but its doing my head in.

The if statement works ish...

Lets say the valve is positive, the colour works, the valve then changes on a update to a negative the colour turns red. As the statement is designed to do.

However, the the valve goes back to a positive after a update the colour stays red?

Any ideas?

Sorry once again

Reply to this topic