How to evaluate a numeric table using a pointer table

I created a pointer table where each element points to a series of numeric tables. I am using a loop to choose the corresponding numeric table using the pointer table. Once I choose the numeric table I want, I need to read the values. The problem that I’m having is that I do not know how to read these values when I’m using a pointer. Does anyone know how to do this?

Assuming I’m understanding your question/situation correctly, you’ll need a pointer to an Integer Table for de-referencing.

You’ll point it to an element in your pointer table. Then you’ll just use it like a regular table except you’ll have that * in front of your pointer to access the Numeric Table it points to.

Here’s a short snippet:

pntCurrentList = ptListOfLists[0]; // get the first element out of the pointer table
nMyValue = *pntCurrentList[2];  // get the 3rd element from that numeric table

Longer snippet:


ptListOfLists[0] = &ntList00;// this numeric table is filled with 0
ptListOfLists[1] = &ntList01;// this table has 1s
ptListOfLists[2] = &ntList02;// this table has 2s


// initialize variables for the loop
nIndex = 0;
pntCurrentList = ptListOfLists[0];

// Loop through the pointer table
repeat
  
  // get the 3rd element in this current numeric table
  nMyValue = *pntCurrentList[2]; // nMyValue will be 0, 1, then 2 as the loop repeats

  // increment the list we're looking at
  IncrementVariable(nIndex);
  
  if (nIndex == GetLengthOfTable(ptListOfLists)) then
    pntCurrentList = NULL; // to get out of the loop
  else
    pntCurrentList = ptListOfLists[nIndex];
  endif

until ( pntCurrentList == NULL );

Hope that helps!
-OptoMary

Mary -

I’ve been trying to do this as well - basically reference a table through a table pointer. (for 2 days now!) So I stumbled on this post, cut and copied your code to a script window, and created the necessary entities… pointer table, pointer, 3 tables, 2 variables, etc. When I test compiled it, I got an error at the same place that Ive been getting one for my own code.

It doesn’t like line 14

nMyValue = *pntCurrentList[2]; // nMyValue will be 0, 1, then 2 as the loop repeats
Compiling…
Error on line 14: syntax error at or near "["
1 error(s), 0 warning(s)

Since I’ve been getting the same error when I compile my own code using table pointers, I’d figure I’d run it by you.

Any insight??

Thanks!
Brian

I would carefully check your data types. pntCurrentList should be a pointer that points to a numeric table.

Yep - that’s it - was an int32. Thanks!!