Hey all you table users out there,
I just came across this code and realized I’ve neglected to mention a couple of commands that should be your friend.
Here’s the code I saw (and was tediously stepping through in PAC Control’s debugger, on my way to the code I REALLY wanted to debug):
// Initialize the string tables
for i=0 to 99 step 1
DstStrTblHdr[i] = "";
DstStrTblBody[i] = "";
next
Here’s the better way to initialize those two string tables:
// Initialize the string tables
MoveToStrTableElements("", 0, -1, DstStrTblHdr);
MoveToStrTableElements("", 0, -1, DstStrTblBody);
Note: check out the “-1” in there: a handy shortcut for this an other table commands where you can skip the “End Index” and just tell the command: “do the whole table.” Neat-o!
Not only is this code easier to step over than the original, but it’s also easier to maintain because it’ll work even when you change the size of your table. (Notice in the original code, if your table went from 100 elements to 200, you might have a hard-to-find bug.)
There’s also a similar command for numeric tables, like this:
// Initialize the numeric table
MoveToNumTableElements(22, 0, -1, ntMyFavoriteNumbers);
That’s how I like to “set the table”! Har. Bad table pun. Couldn’t resist.
-OptoMary