Andrew B
|
| Posted: 11/06/2002, 3:25 PM |
|
Ran into a little problem today. I have a bunch of labels that are floats, which convert themselves into percentages the standard way (via the Format property : '0%'. I needed to format these fields as red or green depending on the value (<1 = red, >1 = green). To do this easily I modified the clsControl class and added 4 variables and a function, and slightly modified the 'show' routine. I added PreText/PostText and HtmlStyle/HtmlClass variables. I had to modify the class because I could not set the value/text properties for the label if I did not change the type to 'text', which would make me loose the auto-formatting, etc. Here is what I did
-- on the page ---
Create custom code for each of the fields to format. Put this code in each one (changing the control name on the first line, of course :
Function retailer_detail_Parts_Prog_BeforeShow()
'Custom Code @127-73254650
dim this : set this = retailer_detail.ActInvty_Prog
if this.Value > 1 then This.HtmlStyle = "color:green" else ...
...
End Function
-- modifications to clsControl in common->classes.asp -------
class clsControl
...
+ Public HtmlStyle
+ Public HtmlClass
+ Public PreText
+ Public PostText
...
--- modifications to the
Sub Show(Template)
Select Case ControlType
Case ccsLabel, ccsTextBox, ccsTextArea, ccsImage, ccsHidden
If HTML Then
+ TemplateBlock.Variable(Name) = ExtendedText(TextValue)
Else
...
+ TemplateBlock.Variable(Name) = ExtendedText(sTmpValue)
End If
End If
-- Additional function to do the real work -----------
public function ExtendedText(sTextValue)
dim sRet
dim sTValue : sTValue = "{value}"
dim sTCss : sTCss = "<font style=""{style}"" class=""{class}"">" & sTValue & "</font>"
If not(IsEmpty(HtmlStyle)) or not(IsEmpty(HtmlClass)) then
sRet = sTCss
Else
sRet = sTValue
End If
'-- replace style/class. If either one is true, both values will be there ---
if not(isEmpty(HtmlStyle)) then
sRet = Replace(sRet, "{style}", HtmlStyle)
else
sRet = Replace(sRet, "{style}", "")
if not(isEmpty(HtmlClass)) then
sRet = Replace(sRet, "{class}", HtmlClass)
else
sRet = Replace(sRet, "{class}", "")
'-- if we have pre/post text, add it to our value
if not(isEmpty(PreText)) or not(isEmpty(PostText)) then
sTextValue = PreText & sTextValue & PostText
end if
sRet = Replace(sRet, "{value}", sTextValue)
ExtendedText = sRet
end function
Hope this helps someone who might run into this problem. Now I can still let CC do all the formatting, etc. and all I have to do is check the value and apply a style to it (or pre/post text). Not really final, just a hack. If you want more info post or email backer_a@hotmail.com
|
|
|
 |
Andrew B
|
| Posted: 11/06/2002, 3:48 PM |
|
I modifed some of the lines so they would not be too long by breaking the if staements into multiple lines.
'-- replace style/class. If either one is true, both values will be there ---
... if statements
They do not work this way. You can either add an 'end if' to each one or you can put them on a single line. You can also add underscores to the end to 'continue' the line but keep the if on multiple lines, like such
if (condition) then _
_
else _
_
|
|
|
 |
|