ATTENTIONThis FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices. |
flexsim.com |
#1
|
|||
|
|||
Variable variable name
Can I define a variable name that is variable itself?
For example: for(i=0; i<=imax; i++) { string concat("product ",numtostring(i), " number") = dbgettablenum(i,1) } Each one of the product number should be valued by the number in the current table cell AND named by the number of the current row. product 1 number = 25 (first table row, first table col) product 2 number = 32 (second table row, first table col) product 3 number = 75 (third table row, first table col) Thanks a lot! |
#2
|
|||
|
|||
In short, no. Flexscript follows C programming rules so I'd try and find some basic tutorials to get a feel of what you can and can't do.
You could create them in the global variables, but then you can't reference them programatically like you do in your example without constructing strings to execute as separate pieces of code. Referring to them explicitly will work, but then your code isn't generic. I'd suggest leaving the data in a table and reading from the part row when you need the number value? Or copy the information to labels on the parts. I think there may be many alternatives for what you're trying to do - perhaps you could further explain your objective. |
#3
|
|||
|
|||
My objective is to build a model out of an access database. The access database contains information about the product and process structure and the flexscript programm should build a model according to this structure.
To do this, I build a loop so that the programm can build object by object in the order given by the structure. I'd like to set treenode variables to every object created. These treenode variables should be named by "their" number in the database. For Example the treenode variable pointing the combiner1 should be named combiner1. And in the loop, the treenode variables should be named combiner(i) The purpose of these variable is that I want to precisely point every object and don't have to guess the rank every time. This should help me to set the location of every object and to connect these object. The location of an object should depend to the locations of the successor, for example: setloc(concat(Combiner, numtostring(i)), xloc(concat(Combiner, numtostring(i-1)))+5) contexdragconnection(concat(Combiner, numtostring(i)), concat(Combiner, numtostring(i-1)), "A) Generally, because the model is build in loops, most of the variables should have "loop" names like xyz(i). Thanks! |
#4
|
||||
|
||||
executestring()
I guess what you are looking for is to concat FlexScript commands and execute them.
I asked the developers for such a command and they put it, what I really appreciate, even if it seems that I am the only one who uses this command. J Anyway, I guess what you are looking for is this command which is called executestring(). Here comes some code which uses this command and is hopefully what you are looking for. Code:
// SET THE LOCATION OF THREE PROCESSORS (Processor1, Processor2 and Processor3) 4 METRES IN X DIRECTION for(int iCounter = 1; iCounter <= 3; iCounter++) { string sCurrentObject = concat("node(","\"","/Processor",numtostring(iCounter,0,0),"\"",",model())"); executestring(concat("setloc(",sCurrentObject,",","xloc(",sCurrentObject,") + 4",",","yloc(",sCurrentObject,")",",","zloc(",sCurrentObject,")",");"),NULL,NULL,NULL); } // SET THE LOCATION OF THREE PROCESSORS (Processor1, Processor2 and Processor3) 4 METRES IN X DIRECTION for(int iCounter = 1; iCounter <= 3; iCounter++) { treenode CurrentObject = executestring(sCurrentObject,NULL,NULL,NULL); executestring(concat("setloc(","(c)",",","xloc(","(c)",") + 4",",","yloc(","(c)",")",",","zloc(","(c)",")",");"),CurrentObject,NULL,NULL); } I am pretty sure that you can use this command to fit into your code.
__________________
tom the (A)tom: "We have solved our problems ... now we have to fight the solutions." |
The Following User Says Thank You to Tom David For This Useful Post: | ||
Congshi Wang (08-03-2010) |
#5
|
||||
|
||||
If you want to add variables with numbers, you should just use arrays. It will be less complicated, faster, and easier to read:
Code:
int imax = 3; treenodearray combiner = makearray(imax); intarray productnumber = makearray(imax); for(int i=1; i<=imax; i++) { combiner[i] = node(concat("/Combiner",numtostring(i)),model()); productnumber[i] = 5; } for(int i=2; i<=imax; i++) { setloc(combiner[i],xloc(combiner[i-1])+5,0,0); addlabel(combiner[i],"ProductNum",productnumber[i]); } Last edited by Phil BoBo; 08-03-2010 at 08:51 AM. Reason: missing parenthesis |
The Following 3 Users Say Thank You to Phil BoBo For This Useful Post: | ||
Tom David (08-03-2010) |
Thread | Thread Starter | Forum | Replies | Last Post |
global variable in DLL (UserFuncs.h) | Esther Bennett | Q&A | 7 | 09-12-2012 07:02 PM |
Global variable as experiment variable | Matthias Hofmann | Q&A | 3 | 09-08-2009 09:42 AM |
Variable Operator | Michael Hartlieb | Q&A | 2 | 07-06-2009 03:53 AM |
Flexsim Please Help - 99 Variable Limit | Joe Allen | Q&A | 13 | 11-19-2008 12:03 PM |
Display Global Variable | Sung Kim | Q&A | 4 | 02-24-2008 11:24 PM |