question

Tee Hiett avatar image
0 Likes"
Tee Hiett asked Tee Hiett commented

How can I use the concat command to create a global variable name?

In the code listed above, I would like to use name created in line 15 as the name of the global variable to receive the time value instead of using the switch command in line 20.Since the integer variable Counter contains the numeral which is in the middle of the name of the global variable I thought I could use the concat command to create the name and use that in lieu of the switch command but I couldn’t get that approach to work. Of course, it doesn’t make any difference in the simple model but some of our clinics have 30-40 providers and creating the name of the global variable would be helpful. Besides, I would just like to know.

Any suggestions?

Tee

PS: I used the FlexSim Answers to find the concat command. I couldn’t find it in FlexSim Users Help.

FlexSim HC 5.1.0
flexsim commandshealthcareconcat
puiar.png (35.8 KiB)
5 |100000

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

Phil BoBo avatar image
3 Likes"
Phil BoBo answered Tee Hiett commented

You can use the executestring() command to execute a string that you concatenate together:

executestring(concat("LastPCI",numtostring(Counter),"TimeNum = getsimtime();"));
· 1
5 |100000

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

Tee Hiett avatar image Tee Hiett commented ·

This method works perfectly. Thanks for joining in.

Tee

0 Likes 0 ·
Steven Hamoen avatar image
2 Likes"
Steven Hamoen answered Tee Hiett commented

@Tee Hiett isn't it possible to just use a global variable array? That way you don't have to mess around with the name but just access the value directly with "Counter"

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

Tee Hiett avatar image Tee Hiett commented ·

Steven, I am not familiar with the global variable array feature. Do you happen to have an example of how it is used? Maybe Mathew will let us know if he thinks it would work in this case. Thanks for your help. Tee

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Tee Hiett commented ·

You select an Array type from the Type dropdown on the Global Variables window.

Then you can access each element in the array using variableName[IndexNumber] syntax, such as:

LastPCITimeNum[Counter] = getsimtime();

0 Likes 0 ·
Tee Hiett avatar image Tee Hiett Phil BoBo ♦♦ commented ·

This method works perfectly. Also the graphic clearly explained the process as well as demonstrating the use of script. Thanks for joining in.

Tee

0 Likes 0 ·
Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered Tee Hiett commented

There's not really an easy way to do this with the way global variables are set up. The main issue is that the variable's value is stored in memory and the only way to set it is using the LastPCITimeNum = value method.

You can use the name to find the node in the tree where the initial value is stored and update its initial value by setting the value on that node. Then you would have to call the refreshglobalvariables command which resets the global variable's value in memory to its initial value. You would also want to reset this value to the original value and call refreshglobalvariables on reset, otherwise your variable would never be reset to its initial value.

As you can see this would require a fair bit of code to navigate the tree and "hack" the global variable system. I personally wouldn't recommend doing that though.

The concat command is in the User Manual. If you open Help > Commands you'll see an alphabetical list of commands. You can also switch to a list grouped by category, an alphabetical index, or a category index in Quick Properties.

· 1
5 |100000

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

Tee Hiett avatar image Tee Hiett commented ·

Thanks, for the explanation, Matthew.

I know that the comcat command is in the list of commands. My problem was that nowhere in the usual manual is the word concatenate identified with the command comcat. Who would think to search for the word comcat? I have searched through the list of commands several times but somehow I never found comcat.

Anyway, I know about that now :-).

Tee

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

You can use the classic technics of tables, labels or nodes to store or receive data. You build your own user command which contain a string to identify the storage place to get the value and optional a value to write new values. In the logic of your user command you translate the string and use an easier name structure for Flexsim.

5 |100000

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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