Hi Darren.
Use a script below.
"{M:WHITE}" attaches the material to the text object (in my opinion works only v.10 and higher, in м.7 it definitely doesn't work)
Dim txtObj As xpTextObject
Dim numValue As Double
self.GetObjectByName("DOW JONES CHANGE", txtObj)
If Double.TryParse(txtObj.Text, numValue) Then 'the script does not stop if the text is not a number
If numValue > 0 Then
txtObj.Text = "{M:STOCKS GREEN}" & txtObj.Text
ElseIf numValue < 0 Then
txtObj.Text = "{M:STOCKS RED}" & txtObj.Text
Else
txtObj.Text = "{M:WHITE}" & txtObj.Text
End If
End If
And if the script doesn't work, try using the script below. You will need to create three fonts with three colors: white, red and green. The script applies the corresponding font to the text object
Dim txtObj As xpTextObject
Dim numValue As Double
self.GetObjectByName("DOW JONES CHANGE", txtObj)
Dim temptxt as String = txtObj.Text
txtObj.Text = ""
If Double.TryParse(temptxt, numValue) Then
Dim font As xpFont
If numValue > 0 Then
self.Project.GetFontByName("STOCKS GREEN", font)
ElseIf numValue < 0 Then
self.Project.GetFontByName("STOCKS RED", font)
Else
self.Project.GetFontByName("WHITE", font)
End If
txtObj.CurrentFont = font
End If
txtObj.AppendToLine(0, temptxt)
------------------------------
Roman Yaroshenko
chief specialist
RBC-TV
Moscow Russian Federation
------------------------------
Original Message:
Sent: 04-03-2025 21:20
From: Darren Johnson
Subject: Changing Text Color based on Positive or Negative
Hello,
I want to have a text object change to Red or Green depending on if the number inputted is negative or positive. I tried using visual logic but it doesn't like (-) or (+) and seems to break when the number contains a comma.
I tried to create a script for it:
dim txtObj as xpTextObjectdim numValue as doubleSelf.getObjectByName("DOW JONES CHANGE", txtObj)numValue = cDbl(txtObj.Text)If numValue > 0 then txtObj.setMaterial(0, "STOCKS GREEN")elseIf numValue < 0 then txtObj.SetMaterial(0, "STOCKS RED")else txtObj.SetMaterial(0, "WHITE")end If
It compiles correctly but doesn't change the text object it's attached to.
Thanks in advance!
------------------------------
Darren Johnson
Director
WFFT
------------------------------