PDA

View Full Version : InputBox in Flexsim script


AlanZhang
06-08-2008, 01:58 AM
A missing (as far as I know) but very useful feature in Flexsim script is a simple InputBox. You may wonder why we need a simple InputBox since we can create all kinds of GUIs. Well, if you use createview to display a window, the code after the createview will continue to execute and sometimes you do not want that.

In the attached model, I created user commands to show a simple InputBox and get the user inputs as a string. Flexsim DLL is used to create the commands.

Two user commands are provided. Basically they works the same but using slightly different methods to create. The dllinputbox command using parstr to passing strings as parameters. According to a post by Anthony(http://www.flexsim.com/community/forum/showthread.php?t=184&highlight=usercommand+string), you can use parstr to parse strings but you may get memory leaking. Keeping that in mind, the other user command, inputbox, uses treenodes to hold strings so there is definitely no memory leaking problem. So you should use inputbox command to be safe. Both user commands returns a treenode (returned as a double since user command can only return double) which stores the user inputs as a string. Then you have to use gets(tonode(inputbox())) to get the result.

The attached DLL InputBox.zip includes the demo model and the dll file. Unzip the files to the same directory. The demo model has a script window open. Simply click the Execute button and type something in the inputbox. The retured user inputs will be printed out in the Output window. If you want user input numbers, you can use stringtonum command to cast the results to numbers.

The attached DLL Project.zip includes a Visual Studio 2008 project which has all C++ source code.

The InputBox is not perfect yet since when the InputBox is open, the Flexsim main window still response to mouse actions. I do not know how to fix it. Maybe Anthony or some other guy in Flexsim can do something about it.