question

Mohamed Slama avatar image
0 Likes"
Mohamed Slama asked Mohamed Slama commented

use the value of an index (i) of a loop and put it in the title of a label

Hi everybody,

In my model, I want to use the index of my loop in the title of a label. Could you please help me to do that ?

  1. for( i=1 ; i<=400 ; i++)
  2. {
  3. if(table[i][2] !=0)
  4. {
  5. current.machine"i" = table[i][3];
  6. }
  7. }

I want to use the value of the index 'i' into the title of a label.

Choose One
labelsloopvalueindex
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Mischa Spelt avatar image
1 Like"
Mischa Spelt answered Mohamed Slama commented

You cannot do this with the dot notation, you need to explicitly construct the name of the label:

  1. for( i=1 ; i<=400 ; i++)
  2. {
  3. if(table[i][2] !=0)
  4. {
  5. string labelName = "machine" + numtostring(i, 0, 0);
  6. current.labels.assert(labelName).value = table[i][3];
  7. }
  8. }

Alternatively, can I suggest that you use a single array-valued label? For example, something like:

  1. current.machines = [];
  2. for( i=1 ; i<=400 ; i++)
  3. {
  4. if(table[i][2] !=0)
  5. {
  6. current.machines.push(table[i][3]);
  7. }
  8. }
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.