question

Ankur A3 avatar image
0 Likes"
Ankur A3 asked Jason Lightfoot edited

Increment ID with local Variable?

Hi Team,

I am facing issue while incrementing label "ID" value using local variable.

Can anybody help me how to write code for it?

Thank you!

Test_Increment_ID_With_Local_Variable.fsm

FlexSim 20.0.10
incrementlocal variable
5 |100000

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

Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Jason Lightfoot edited

You're incrementing a local variable that you're not initialising to an explicit value but will usually be zero. Use a global variable, eg. myID, instead of the local one. The you can use it in the label assigment directly with the increment operator++:

1651929211472.png


test-increment-id-with-local-variable_jl.fsm


· 2
5 |100000

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

Ankur A3 avatar image Ankur A3 commented ·
Hi @Jason Lightfoot,

Thank you for your answer!

But I am looking for approach using local variable only. The reason is I have to use hundreds of variable in my model. I don't know if defining global variable every time is effective approach?

What would your suggest in such case? Will you still recommend to use global variable?

Thank you!

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Ankur A3 commented ·

Then put a label on an object and increment that. The question is how many distinct incrementing counters do you want and how are they grouped/partitioned?

0 Likes 0 ·
Joerg Vogel avatar image
1 Like"
Joerg Vogel answered

combining Token.ID and table rows is not an recommended approach, because there are other processes under the hood which can create tokens,too. You should think about to set a process flow label for such a task, where you link an ID value to numbers of rows in tables. Or you you evaluate your table directly to get numbers of rows by property numRows.

5 |100000

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