DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

"Conditional Formatting" in DIAdem

Is it possible to have "conditional formatting" (that is what it is called in Excel) in DIAdem report?

I would like to display channels in a 2-D table and if values in a channel are out of a specified range I would like those values to be a different format. Is this possible? I have not worked much with scripting functions for REPORT so I would appreciate help!

Julia
0 Kudos
Message 1 of 11
(5,006 Views)
Hi Julia,

you can achieve that goal with an user function. User functions can be added in the section "Settings"->"Desktop parameters"->"User commands...".

In this user function you can change the font properties. The user function could look like that:

public function MyResult(row, column, channel)
dim Value
Value = chdx(row, cno(channel))
'Change the font properties for values greater 0
if (Value>0) then
D2TABNUMCOLOR(column) ="red"
D2TABNUMBOLD (column) =1
else
D2TABNUMCOLOR(column) ="black"
D2TABNUMBOLD (column) =0
end if
'Formatting the numerical value
MyResult = str(Value,"d.dd")
end function

To use this function now in a 2D-table you have to choose the data type "expression" and a value like "@@MyResult(D2TabRow, D2TabCol, "Speed")@@".


Stefan
0 Kudos
Message 2 of 11
(4,993 Views)
That is great, thank you for your help!
0 Kudos
Message 3 of 11
(4,974 Views)
One further question, I was trying to change the background color of the cells and thought I would use "D2TabBackColor" for this but nothing happens...my function is below as well as what I am using in my expression.

Public Function TranValue(Channel, MinChn, MaxChn)
Dim Value, MinValue, MaxValue
Value = ChDX(1,CNo(Channel))
MinValue = ChDX(1, CNo(MinChn))
MaxValue = ChDX(1, CNo(MaxChn))
If (Value > MinValue) AND (Value < MaxValue) Then
D2TabBackColor = "dark green"
Else
D2TabBackColor = "red"
End If
TranValue = Str(Value, "d.dd")
End Function

@@TranValue("Channel","MinChannel","MaxChannel")@@

Thank you, Julia
0 Kudos
Message 4 of 11
(4,941 Views)
Hi Julia,

D2TabBackColor is not a per cell property, it’s a global 2D table property to change the back color of the whole table. You can change this property only in advance, not during the drawing of the cells. Only the following properties can be changed while drawing the cells:

D2TabNumColor()
D2TabNumColorRGB()
D2TabNumFont()
D2TabNumBold()
D2TabNumItalic()
D2TabNumUndl()
D2TabNumStrOut()
D2TabNumSize()

A possible function would be:

Public Function TranValue(Channel, MinChn, MaxChn)
Dim Value, MinValue, MaxValue
Value = ChDX(1,CNo(Channel))
MinValue = ChDX(1, CNo(MinChn))
MaxValue = ChDX(1, CNo(MaxChn))
If (Value > MinValue) AND (Value < MaxValue) Then
D2TabNumColor(D2TabCol) = "dark green" 'In D2TabCol the current column is stored
Else
D2TabNumColor(D2TabCol) = "red"
End If
TranValue = Str(Value, "d.dd")
End Function


Stefan
0 Kudos
Message 5 of 11
(4,932 Views)
Thank you, changing the text format should be sufficient for my application. I appreciate your help.
0 Kudos
Message 6 of 11
(4,914 Views)

Is it possible to change the property of a channel in Report depending on its value?

This is what the statement looks like in Report,

: @str(ChnPropGet("[1]/Accel Peakge60","e60"),'dd.ddd')@ g

If the value goes over 20, I would like it to change colour.

Thanks

0 Kudos
Message 7 of 11
(4,635 Views)

Hello Stagsden,

The following code should do what you want. Please change the "Text1" parameter to the name of the text object you are using to display the channel property you are referring to.

IF ChnPropGet("[1]/Accel Peakge60","e60") > 20 THEN
  Call GraphObjOpen("Text1")
    TXTCOLOR         ="red"
  Call GraphObjClose("Text1")
END IF

Let us know if you have any more questions,

Otmar

Otmar D. Foehner
0 Kudos
Message 8 of 11
(4,618 Views)

I'm not sure if this is any easier for you, but an alternate method would involve registering a user command like the script below and in a REPORT text object using the following as your text:

@@MyResultText("Text2", "MyChannelName", "maximum", 250)@@

Where "Text2" is the REPORT text object name, "MyChannelName" is the channel you are referencing. 

There may be easier ways to do this also, but this is similar to how I use "conditional formatting" in DIAdem.

'---script begin---

Option Explicit  'Forces the explicit declaration of all the variables in a script.
Call ScriptCmdAdd(AutoActFile) ' Adds the user command
Public Function MyResultText(TextObjName, ChanName, ChnProp, DNEValue)
  Dim ChnPropValue
  ChnPropValue = ChnPropValGet(ChanName, ChnProp) ' note that ChnPropValGet only works in DIAdem 10.1 +
  ' Change the font properties for values greater than DNEValue
  Call GraphObjOpen(TextObjName)
  If ChnPropValue > DNEValue Then
    TxtColor = "red"
  Else
    TxtColor = "green"
  End If
  Call GraphObjClose(TextObjName)
  MyResultText = Str(ChnPropValue,"d.dd")
End Function

'---script end---

0 Kudos
Message 9 of 11
(4,612 Views)

I think that should work when I have renamed all of my objects in Report, as I have about 20 text objects and none of them have unique names.

Or can I call them individually by their channel property.

Thanks

0 Kudos
Message 10 of 11
(4,607 Views)