Move string table to string table?


#1

Hi - I do not see a function to move a string table to a string table like the instruction “move table to table”, moving a string table is not an option using this instruction.

Is there a function that does this? Or is there another way to do this other than moving every index individually?

Thanks!!


#2

Clarification, this is in factory floor


#3

Hello Carrie,

Welcome to the OptoForums! You’re right, that’s not a built-in command. In PACs/Ultimate I/O you have a few options (any chance you’ll be upgrading soon)?

In both PAC Control and OptoControl you can write your own command to do this (a subroutine, check out [U][B]this post on subs[/B][/U]).

However, if you use an [B]for [/B]loop in OptoScript (the yellow hexagonal block), it’s just a few lines of code like this:


// loop through table index values 0 through 9 and move value in stTableFrom to stTableTo

for nTableIndex = 0 to 9 step 1

  stTableTo[nTableIndex] = stTableFrom[nTableIndex];

next

Or if you want to get a little fancier, especially if the lengths of those tables might change or might be different from each other, you can add some sanity checking before the loop like this:


// Get the lengths of my 2 string tables
nTableLength1 = GetLengthOfTable( stTable1 );
nTableLength2 = GetLengthOfTable( stTable2 );

// Figure out which one is smaller, so I don't run off the end 
nStringsToCopy = Min( nTableLength1, nTableLength2 );

// Loop through each index until we run out of them and copy from Table1 to Table2
for nTableIndex = 0 to (nStringsToCopy - 1) step 1

  stTable2[nTableIndex] = stTable1[nTableIndex];

next

I know OptoScript isn’t for everyone, but when it comes to strings and loops especially, it can save you some time!

-OptoMary