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 01-12-2010
Nico Zahn's Avatar
Nico Zahn Nico Zahn is offline
Flexsim User
 
Join Date: Sep 2007
Location: Bingen am Rhein, Germany
Posts: 179
Downloads: 19
Uploads: 4
Thanks: 66
Thanked 60 Times in 32 Posts
Rep Power: 201
Nico Zahn has a spectacular aura aboutNico Zahn has a spectacular aura about
Default 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.
  #2  
Old 01-12-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

Passing strings into user commands works fine in 4.52 with no compiler errors. What compiler errors are you getting?
  #3  
Old 01-12-2010
Nico Zahn's Avatar
Nico Zahn Nico Zahn is offline
Flexsim User
 
Join Date: Sep 2007
Location: Bingen am Rhein, Germany
Posts: 179
Downloads: 19
Uploads: 4
Thanks: 66
Thanked 60 Times in 32 Posts
Rep Power: 201
Nico Zahn has a spectacular aura aboutNico Zahn has a spectacular aura about
Default

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...
Attached Thumbnails
Click image for larger version
Name:	Screenshot_1.jpg
Views:	247
Size:	64.4 KB
ID:	891  
__________________
kind regards Nico.
  #4  
Old 01-12-2010
Vincent Bechard Vincent Bechard is offline
Consulting in Simulation
 
Join Date: Oct 2008
Location: Montréal (Canada)
Posts: 28
Downloads: 0
Uploads: 0
Thanks: 4
Thanked 41 Times in 13 Posts
Rep Power: 165
Vincent Bechard will become famous soon enoughVincent Bechard will become famous soon enough
Default

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  
Old 01-13-2010
Nico Zahn's Avatar
Nico Zahn Nico Zahn is offline
Flexsim User
 
Join Date: Sep 2007
Location: Bingen am Rhein, Germany
Posts: 179
Downloads: 19
Uploads: 4
Thanks: 66
Thanked 60 Times in 32 Posts
Rep Power: 201
Nico Zahn has a spectacular aura aboutNico Zahn has a spectacular aura about
Default

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  
Old 01-13-2010
Nico Zahn's Avatar
Nico Zahn Nico Zahn is offline
Flexsim User
 
Join Date: Sep 2007
Location: Bingen am Rhein, Germany
Posts: 179
Downloads: 19
Uploads: 4
Thanks: 66
Thanked 60 Times in 32 Posts
Rep Power: 201
Nico Zahn has a spectacular aura aboutNico Zahn has a spectacular aura about
Default

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  
Old 01-13-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

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


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.