ATTENTION

This 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

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 08-02-2010
Congshi Wang Congshi Wang is offline
Student
 
Join Date: May 2010
Location: Germany
Posts: 58
Downloads: 2
Uploads: 0
Thanks: 48
Thanked 0 Times in 0 Posts
Rep Power: 124
Congshi Wang is on a distinguished road
Default 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  
Old 08-02-2010
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 773
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

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  
Old 08-02-2010
Congshi Wang Congshi Wang is offline
Student
 
Join Date: May 2010
Location: Germany
Posts: 58
Downloads: 2
Uploads: 0
Thanks: 48
Thanked 0 Times in 0 Posts
Rep Power: 124
Congshi Wang is on a distinguished road
Default

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  
Old 08-03-2010
Tom David's Avatar
Tom David Tom David is offline
Flexsim User
 
Join Date: Aug 2007
Location: Schwaebisch Gmuend, Germany
Posts: 430
Downloads: 157
Uploads: 47
Thanks: 486
Thanked 450 Times in 233 Posts
Rep Power: 520
Tom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant future
Default 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);
}
In the first example I used a string as a "pointer" in the second I used the "c" and point in the second parameter of the executestring command.

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  
Old 08-03-2010
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

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


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.