Page 1 of 1

Feedback if GAMS code has been executed successfully

Posted: Mon Jan 11, 2021 6:47 pm
by Janisch
Hello all,

Is there any way to find out if the optimization that I run from excel via a batch file has been successful, so there were no errors in the code execution in GAMS?
I always see only the cmd window. But even if there is a syntax error in the code, it is not reported back to me.

Maybe someone knows and can help me. If still missing info just let me know.

Janisch

Re: Feedback if GAMS code has been executed successfully

Posted: Mon Jan 18, 2021 6:56 pm
by Janisch
In VBA I have the following lines of code:

Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
Dim errorCode As Long
errorCode = wsh.Run(ThisWorkbook.Path & "\mymodel.bat", windowStyle, waitOnReturn)

And the batch file following lines of code:

cd /D %~dp0
C:\GAMS\33\gams mymodel.gms

Unfortunately, I always get the error code 2 when i running the batch file even if I have no syntax errors in my GAMS model.
Because actually the number 0 should be returned for a normal execution. Or i am wrong?
https://www.gams.com/latest/docs/UG_GAM ... odes.html

Does anybody know my mistake?

Re: Feedback if GAMS code has been executed successfully

Posted: Tue Jan 19, 2021 6:36 am
by bussieck
What does the LST file say. That's the prim location to look for compilation errors.

Re: Feedback if GAMS code has been executed successfully

Posted: Tue Jan 19, 2021 8:43 am
by Janisch
If there is a syntax error it will show me in GAMS Studio when I start the optimization from there. If I call the batch file in Excel and thereby start the optimization. The cmd console opens, I see briefly the GAMS code and then the return code 2 is returned again. But even if there is no error, Return Code 2 is always returned.

Are there any other possibilities to output the return code in VBA via the batch file?

Re: Feedback if GAMS code has been executed successfully

Posted: Wed Jan 20, 2021 9:18 am
by bussieck
Put a "echo %errorlevel%" after the gams call (to see GAMS return code) and a "pause" in your cmd script to see what's going on.

-Michael

Re: Feedback if GAMS code has been executed successfully

Posted: Wed Jan 20, 2021 5:04 pm
by Janisch
Thanks for your help :) Now it works!