question

Scott Ainsworth avatar image
0 Likes"
Scott Ainsworth asked Matthew Gillespie commented

Why does my integer variable not set from label?

I'm trying to process some tokens by case with a switch command that requires an integer.

I have some custom code that looks up a WType string in a table and assigns an WTypeVal label to the tokens. I want to use WTypeVal in the switch command. However, I seem to only get 0 assigned to the integer variable Wtype. I've tried a dozen variations with the same result. I've posted a pic of the model. It is difficult to post the whole model as there is client proprietary info in it.

As you can see the custom code is in a subprocess. The token in question has WTypeVal of 3. I only get Wtype of 0. I assigned 15 to Wtype just to prove it changes to 0.

It seems that Parent, Child relationship is a bit fuzzy going to a subprocess with custom code because many of the Label names do not show up in the pick list when entering code.

Any help is appreciated.

wtype-not-set.jpg

Scott

FlexSim 18.2.2
process flowlabelscoding
wtype-not-set.jpg (135.1 KiB)
· 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.

Matthew Gillespie avatar image Matthew Gillespie ♦♦ commented ·

Depending on what parent label access you gave the child token it's possible that token.parent.WTypeVal is different than token.WTypeVal.

Can you attach the model?

0 Likes 0 ·
Scott Ainsworth avatar image Scott Ainsworth commented ·

Parent Label Access is set to Read Write in the Run Sub Flow block. I've tried "Label Access on Parent Only" and "Copy Labels to Children on Create". I've also tried assigning a label WTypeVal with token.WTypeVal as the value. It still returns a 0 in the sub process code shown. I'm baffled.

0 Likes 0 ·
Scott Ainsworth avatar image Scott Ainsworth commented ·

I ran this bit of code prior to the sub flow call. It must be something to do with how the label is created. As you can see bill and bob are both assigned the same way in the code. bob is gets 0 and bill gets 3. Both labels have a value of 3 in the token.

The WTypeVal is set with the attached code, where as the SashFactor is set with an assign labels command. wtypeval-assignment.txt

I'm not sure what I've done wrong.

0 Likes 0 ·

1 Answer

Raja Sekaran avatar image
1 Like"
Raja Sekaran answered Matthew Gillespie commented

@Scott Ainsworth

Since you are saying like "I have some custom code that looks up a WType string in a table and assigns a WTypeVal label to the tokens."

Make sure that you are getting the number type as a value in the label. If you are getting a label value as string type then you have to convert that into number type using toNum() or stringtonum() command.

· 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.

Scott Ainsworth avatar image Scott Ainsworth commented ·

@Raja Sekaran

You are correct. I added stringtonum() in the command that assigns the label and now the value is read properly.

Thank You

0 Likes 0 ·
wtypeval-assign.jpg (33.5 KiB)
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Scott Ainsworth commented ·

You could also change the datatype of the table cell (or column) to be number data (through the right click menu). Then you wouldn't have to convert the string into a number later.

0 Likes 0 ·