Why does my integer variable not set from label?

Why does my integer variable not set from label?

scott_ainsworth
Enthusiast Enthusiast
1,728 Views
6 Replies
Message 1 of 7

Why does my integer variable not set from label?

scott_ainsworth
Enthusiast
Enthusiast

[ FlexSim 18.2.2 ]

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

0 Likes
Accepted solutions (1)
1,729 Views
6 Replies
Replies (6)
Message 2 of 7

Matthew_Gillespie
Autodesk
Autodesk

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?



Matthew Gillespie
FlexSim Software Developer

0 Likes
Message 3 of 7

scott_ainsworth
Enthusiast
Enthusiast

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
Message 4 of 7

scott_ainsworth
Enthusiast
Enthusiast

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.

15096-wtypeval-test.jpg

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
Message 5 of 7

raja_sekaran
Not applicable
Accepted solution

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

Message 6 of 7

scott_ainsworth
Enthusiast
Enthusiast

@Raja Sekaran

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

Thank You

15110-wtypeval-assign.jpg

0 Likes
Message 7 of 7

Matthew_Gillespie
Autodesk
Autodesk

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.



Matthew Gillespie
FlexSim Software Developer

0 Likes