LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Table Control: The index passed is out of range

GetTableCellFromValue(panelHandle,PANEL_TABLE,MakePoint(1,1),MakeRect (1,1,noOfRows,1),&pt,VAL_COLUMN_MAJOR,VAL_CELL_STRING,VAL_CHAR,ChNo[0]);
printf("Row:  %d,Col:  %d \n: ",pt.y,pt.x);
GetTableCellVal(panelHandle,PANEL_TABLE,pt,CH_NO);
 
Sometime i get an error "The index passed is out of range" although it prints proper value. Let me mention that i adds rows to the table at run time. In one event i add the rows and in second event when i need to update the row value i called above function. Also let me know how to search into table from bottom to top.
Thanks and Regards
Rakesh
0 Kudos
Message 1 of 7
(5,806 Views)
Hello Rakesh,
 
I was unable to reproduce this behavior on my machine.  The only time I would see this happening is if you try to access a row before it has been programmatically created. First, I would make sure that the default column and row type are set to Hot or Normal mode instead of Indicator mode.  You could use the following line of code to do this:
SetTableCellRangeAttribute (MainPanel, PANEL_TABLE, VAL_TABLE_ENTIRE_RANGE, ATTR_CELL_MODE, VAL_HOT);
 
After doing this, do you see the same behavior.  If you so, could you post an example demonstrating the behavior.  Also, regarding how to search through a table from top to bottom, I believe this has been address in the following post.
 
Thanks.
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 2 of 7
(5,764 Views)

Hello Wendy

Thanks for your support. The problem being resolved by using PostDeferredCall.  I will also try as you have suggested. But search into the table is still an issue since i have to search for Last occurrence of the searched value. Do you have any other idea instead of search from Top to Bottom.

Regarding the memory leak i will attach the code in respective question.

Many thanks

Rakesh 

0 Kudos
Message 3 of 7
(5,761 Views)

Rakesh,

Since you can't use the GetTableCellFromValue function to search backwards, your best bet is to simply implement the search yourself. It's not difficult, especially if you know what kinds of cells and what type of data you're searching through. For example, if you're searching for text data in your table, and you're looking for exact matches, you can do something like this:

GetNumTableRows (panel, ctrl, &numRows);
GetNumTableColumns (panel, ctrl, &numColumns);

for (i = numColumns; i > 0; i--)
{
     for (j = numRows; j > 0; j--)
     {
          PointSet (&cell, i, j);
          GetTableCellValLength (panel, control, cell, &length);
          nullChk(cellText = malloc (length + 1));
          GetTableCellVal (panel, control, cell, cellText);

          if (!strcmp (targetString, cellText))
               break;  // success -- break out of the loop
     }
}

If you are just looking for a partial match, you can use strstr instead of strcmp. If you need to search in column-major order, simply swap the outer loop for the inner loop. If you're looking for numerical data instead, then use a numeric comparison instead. If you have cells of different types, and you need to skip some of them, you might need to interject some extra logic in these loops. If you need to search multiple times, then modify the loop to start at at a particular cell, instead of always starting at the end of the table. You get the idea.

Luis
NI

Message 4 of 7
(5,750 Views)
Thanks Luis
0 Kudos
Message 5 of 7
(5,737 Views)
Rakesh,
 
Actually, just as I was looking at that code again, I noticed that I have a big fat memory leak in that loop (I keep reallocating memory and never freeing it). So please don't use that code exactly as it is... 🙂
 
Luis
0 Kudos
Message 6 of 7
(5,727 Views)

I have taken care Thanks 🙂

Rakesh

0 Kudos
Message 7 of 7
(5,717 Views)