Tuesday, August 25, 2009

How to run QUEST from Excel VBA and wait for QUEST to finish

This post is not meant to show you how you can use VBA to run BCL commands in QUEST. It's just a small tweak to how we run QUEST in this previous post. In that previous VBA solution, I used the baked-in Shell command to run a QUEST.bat file in BCL mode.

One reason I can think of for using this functionality is being able to automatically run some experimentation in QUEST, without having to mess with sockets (until we can get an easy to use library for QUEST sockets). This way we can have some Excel worksheet with accompanying VBA code that will run QUEST, wait for QUEST to exit, then check some output file from QUEST before advancing in the experiment. I am working on a project where this is pretty much exactly what I'll be doing.

To make this work, we just need to use a different Shell command, that will effectively halt execution of our VBA code while QUEST runs, and resume execution once the QUEST process we started ends.

Basically, we will re-use the code found here to replace our basic Shell call. All the linked code does is start QUEST using the Shell command, and uses a few Windows API calls to monitor the QUEST.exe process we started, looping until that process ends. Once the process ends, we exit the loop and VBA continues executing code.

I've updated the QUEST_BCL_Addin.xla file which can be downloaded here to include this new ShellAndWait functionality. If you call the SaveABCL function with LaunchQUEST = True and TransferToMenu = False then your code will wait for QUEST to exit before resuming.

I'd like to start adding some QUEST BCL User Defined Functions to this addin in the near future. I have some written already, but would like to get them properly formatted for release. If you have any you'd like to donate drop me a line using this contact form.

5 comments:

Anonymous said...

Hello John,
I often read your blog and am very interested in interactions between QUEST and EXCEL.
In my area of research, I am trying to achieve an optimization process automatically.I am proceeding in a similar way, but I used ACCESS. The organization of data is more schematic.There are special reasons for using Excel?
For the moment I realized the database and a macro-code that writes a txt file with commands bcl. Thank you for what you write on the blog. After reading what you wrote, I am aware that I can achieve my goal.I am a mechanical engineer. My goal is to create an intelligent and optimization problems specific to the layout. You think some kind of optimization? Want to tackle this?
I think the genetic algorithms.

Congratulations on what you do. Good job

eng. Mauro Sammarco

Zaphod at Home said...

Hi Mauro,
Thanks for the words of encouragement. I'm glad some of this has been helpful to you.

I've been using Excel mainly for building User Defined Functions for many different BCL commands, so I don't have to remember all the syntax for a command; just the name and some arguments.

Also, by using Excel I'm able to create a BCL script to build an entire model, and since Excel can recalculate cells, you sort of end up with a parametric QUEST model that you can easily modify just in a spreadsheet, which a lot more people understand than QUEST.

Any way you do it, I'd say, is cool. Especially if there was a way to tackle layout problems using VBA rather than trying to use SCL.

Thanks again,

Jon

Anonymous said...

Hi Jon,
try to work with code Addin, that loaded in March, but it doesn't work. You said that if I used the first time I must enter the path. where?
thank you

Donna said...

Hi John,
I've inquiry on how to run a model within QUEST from XML schematic data?
Whether we need specific method to run or need other supportive tools to retrieve the data and translates.

Zaphod at Home said...

Hi Cik,
I'm not sure of any in-built XML tools for running QUEST models.

There is an ASCII text format used for the PPR hub, I believe, that you can use as an import format for QUEST.

I have been working on a few packages for commercialization, that deal with building QUEST models from data files. One of these projects is on the Core Manufacturing Simulation Data format (CMSD), which is an XML data format for simulation models.

I hope to be able to talk more about this around the Winter Sim timeframe (mid-December of this year)

-Jon