11-20-2013 09:20 AM
Hello,
Could someone please help me understand how to access table cells (in report)? I have a report with a table populated from a channel. It shows, in one column, a list of names (which come from a channel). I have another channel with a list of colors and I want to associate each name in the table with a color from this second channel. I have tried without success to even access a cell using D2TabRow and D2TabCol and display the contents....
Any help is appreciated
Thanks
Solved! Go to Solution.
11-21-2013 03:14 PM
Hi mrme,
Have you by any chance looked at this forum post and this post?
This code also showes you how to access cells tables in the view, which might be helpful to you.
Dim myChan,chn_Name, chnNum, elementNum
chnNum = 1 'set this to the channel index of the channel you want to access in your table
elementNum = 1 'set this to which element in the channel you want to access
Set myChan = View.ActiveSheet.ActiveArea.DisplayObj.Columns(chnNum)
set chn_Name = Data.GetChannel(myChan.ChannelName)
Msgbox(chn_Name(elementNum))
Hope these information help.
11-21-2013 03:14 PM
Hi mrme,
Have you by any chance looked at this forum post and this post?
This code also showes you how to access cells tables in the view, which might be helpful to you.
Dim myChan,chn_Name, chnNum, elementNum
chnNum = 1 'set this to the channel index of the channel you want to access in your table
elementNum = 1 'set this to which element in the channel you want to access
Set myChan = View.ActiveSheet.ActiveArea.DisplayObj.Columns(chnNum)
set chn_Name = Data.GetChannel(myChan.ChannelName)
Msgbox(chn_Name(elementNum))
Hope these information help.
11-22-2013 06:05 AM
Hi Edna-S,
Yes, I did already look at the mentioned posts, but my problem is at a much more basic level. I would like, for example, to use script to display a MsgBox showing a spcecified entry in a Report table. However, I do not know how to reference a cell (row, col) and extract the entry from that cell. I have not been able to find commands or help on how to do this. is it even possible in Report?
Thank you for the support and effort.
Best regards
11-25-2013 11:15 AM
Hi mrme,
Would it be ok for you to send in your code so that I can better see what you are trying to accomplish?
Also it might be easier to retrieve data from the channel than from table. I attached a code.
11-25-2013 11:15 AM
Hi mrme,
Would it be ok for you to send in your code so that I can better see what you are trying to accomplish?
Also it might be easier to retrieve data from the channel than from table. I attached a code.
11-26-2013 11:28 AM
Hi Edna-S,
Thanks again for the help, but I am stuck at a very basic level. if I can get past that, the rest will work for me. Rather than using channels, I would like to reference elements in a table using the table row and column.
I found the script below in a previous post. Using it, I can create a two column table in Report. I added a little bit to the script and I can also change the font colour for the headers or a column.
But, I cannot figure out how to reference just one cell. If for example, I wanted to change the font colour for the third cell in the second column only, what commands should I use? In other words is there some equivalent of A= chT (row, channel) for use with tables where I could give the cell reference (row,col) and have the entry stored (A) in that cell returned?
Many Thanks!
Dim Length, Ch1, Ch2, GroupIdx
Length = 8
GroupIdx = GetCreateGroup("New Group")
Ch1 = GetCreateChannel(GroupIdx, "New Channel 1", Length)
Ch2 = GetCreateChannel(GroupIdx, "New Channel 2", Length)
For i = 1 to Length
ChDX(i, Ch1) = i
ChDX(i, Ch2) = i+5
Next
Call PicLoad("C:\DiademExercises\Table_test2.TDR")
Call GraphSheetShow("Property_table")
Call GRAPHObjOpen("2DTable1")
D2TABDATATYPE(1) = "Channel"
D2TABCHNNAME(1) = "[" & GroupIdx & "]/" & ChnName(Ch1)
D2TABDATATYPE(2) = "Channel"
D2TABCHNNAME(2) = "[" & GroupIdx & "]/" & ChnName(Ch2)
Call GRAPHObjClose("2DTable1")
Call PicUpdate
'-------------------------------------------------------------------------------------
'******* GetCreateGroup() *** *** NEW Function ***
'-------------------------------------------------------------------------------------
Function GetCreateGroup(GroupNameStr)
Dim ResultsGroupIdx
ResultsGroupIdx = GroupIndexGet(GroupNameStr)
IF ResultsGroupIdx = 0 THEN
Call GroupCreate(GroupNameStr)
ResultsGroupIdx = GroupCount
END IF
Call GroupDefaultSet(ResultsGroupIdx)
GetCreateGroup = ResultsGroupIdx
End Function ' GetCreateGroup()
'-------------------------------------------------------------------------------------
'******* GetCreateChannel() *** *** NEW Function ***
'-------------------------------------------------------------------------------------
Function GetCreateChannel(GroupIdx, ChanName, ChanLength)
Dim ResultChanNum, ChanIdx
ResultChanNum = CNo("[" & GroupIdx & "]/" & ChanName)
IF ResultChanNum = 0 THEN
ChanIdx = GroupChnCount(GroupIdx) + 1
Call ChnAlloc(ChanName, ChanLength, 1, DataTypeFloat64, "Numeric", GroupIdx, ChanIdx)
ResultChanNum = CNoXGet(GroupIdx, ChanIdx)
END IF
ChnLength(ResultChanNum) = ChanLength
GetCreateChannel = ResultChanNum
End Function ' GetCreateChannel()
'-------------------------------------------------------------------------------------
Call GRAPHObjOpen("2DTable1")
D2TabNumColor(2) = "red" 'Changes font in column2 to red
D2TabTxtColor = "blue" 'Puts the header text blue in colour
Call GRAPHObjClose("2DTable1")
Call PicUpdate
12-02-2013 01:09 PM
Hi mrme,
The example Edna has sent you twice shows the only way to change the text font properties of individual table cells. You have to create, register, and invoke a UserCommand, so it's not simple. The main problem you're running into is that the table object in REPORT does not typically contain cells. If you happen to have chosen a column type of "Text list", then you can access the contents of individual table cells, but otherwise your only options are to get and set the values outside of the table that the table is referencing-- be they channels values or variable values or expressions.
The simplest option is to get/set channel values and assign each table column or row to display those channel values.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
12-04-2013 10:43 AM
Hi Brad,
Thanks for the explanation - I had thought there was something simple that I was missing, but it seems not to be so straight forward.
Best regards