I am drawing a 2D able on a report which I have successfully filled with the output I want. It may be important to note that all the cell values are expressions, not channels. It looks like this:
My final step is to change the background color based on the cell value.
Following the example "Using User Commands for Trend Displays in Tables", I saved a separate script with the new command and set up just one column to use it. On testing the script, ALL non-header cell contents disappeared from the table! Now it looks like this:
The new user command is in the file HealthCellBackground.vbs as follows. Note that currently all the contents of the command are commented out, which would theoretically result in no changes to the table, and theoretically couldn't have any hidden bugs in it.
sub TabHealthOnDrawingCell(Context, Cell) dim dCurrVal ' dCurrVal = val(Cell.Value) ' If Context.Col >= 2 AND Context.Col <= 9 Then ' If dCurrVal >= 100 Then ' Cell.BackgroundColor.SetRGBColor(RGB(50, 150, 50)) ' ElseIf dCurrVal >= 25 Then ' Cell.BackgroundColor.SetRGBColor(RGB(175, 230, 200)) ' Else ' Cell.BackgroundColor.SetRGBColor(RGB(255, 50, 50)) ' End If ' End If end sub 'TabHealthOnDrawingCell
The command is registered as:
' Register a REPORT user function, ScriptCmdAdd("D:\LabVIEW\Project\DIAdem\HealthCellBackground.VBS")
The script contents for that column are:
Set o2DTableColumnExpression = o2DTable.Columns.Item(2) Set oColBG = o2DTableColumnExpression.Settings.BackgroundColor oColBG.ColorIndex = eColorIndexFillEffects oColBG.RGBFilling = RGB(147,225,225) oColBG.RGB = vbGreen oColBG.GradientDirection = eColorGradientHorizontal oColBG.GradientMode = eColorGradientModeFromInside o2DTableColumnExpression.Settings.OnDrawingCell="TabHealthOnDrawingCell"
Simply commenting out the last line in the final code snippet above will restore the cell values. The images above were generated by toggling just that one comment character.
Just for sanity, I tried using the command from the example, TabTrendOnDrawingCell_Case1, and it gave the same results. Based on the evidence so far, either something is going wrong with the registration, or it's the cell contents as expressions that cause the issue.
Any ideas?