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
|
||||
|
||||
Passing strings into a usercommand
I am trying to pull up an old modell from 3.0 to 4.5.
My problem is a usercommand which is passing strings as parameters. (is used about 800X in the modell) Something like: createtransport("Table_A","Aim_9","Destination_7", "Prio_LOW"); In the usercommand I use a parstr() to get the strings. Any ideas how to pass the strings into the usercommand without compiler errors? Does anybody know if the errors a relevant, does the usercommand work?
__________________
kind regards Nico. |
#3
|
||||
|
||||
Hi Phil,
This is the error message: 1>..\all.cpp(19912) : error C2664: 'createtransport' : cannot convert parameter 1 from 'const char [4]' to 'double' 1> There is no context in which this conversion is possible Here is the commandcall: createtransport("TAF",getname(current),"PO_LV_03", getlabelnum(item,"Prio"),0,time(),getlabelstr(item ,"Type")); and attached you find a picture of the usercommand code...
__________________
kind regards Nico. |
#4
|
|||
|
|||
Hi,
Have you tried to use something like: tonum(apchar("your string")) It works fine for me when I compile. Vincent Béchard, ing., M.Sc.A. Simulation & optimisation __________________________ SNC-Lavalin Devonyx Inc. 360, St-Jacques O. Montréal (Canada) H2Y 1P5 514-845-2166 #2204 |
#5
|
||||
|
||||
Hi Bernard,
this would work, but there are about 800 commands I would need to change. Hey Phil, do you see a reason why it is not working the way I implemented it?
__________________
kind regards Nico. |
#6
|
||||
|
||||
I found the reason..
The user command was called from a node that was toogled to c++, and in this case you can not pass strings into a usercommand...
__________________
kind regards Nico. |
#7
|
||||
|
||||
The user commands' parameters are all of type double, which is how they work with Flexscript and the parstr(), parnum(), parval() commands. That way they can have a variable number of parameters of any parameter types.
If you call a user command from C++, then you need to cast into a double because C++ is type-specific. So you need to use the tonum() command to cast the string into a number if you are calling the command from C++. The parstr() command casts it back into a string that you can use. If you are using Flexscript to call the command (as I was when I told you that there were no compile errors), then it works just fine no matter what type you are passing. Since there are so many places you need to change, you might want to check out the findInCode user command that Jason Lightfoot developed for finding and changing code easily in many places. http://www.flexsim.com/community/for...ead.php?t=1149 |
The Following 2 Users Say Thank You to Phil BoBo For This Useful Post: | ||
Nico Zahn (01-15-2010) |
Thread | Thread Starter | Forum | Replies | Last Post |
Read strings separated with a semi-colon from an Ascii file | Tom David | Q&A | 4 | 03-15-2010 01:24 PM |