Feedback if GAMS code has been executed successfully

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

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_GAMSReturnCodes.html

Does anybody know my mistake?

What does the LST file say. That’s the prim location to look for compilation errors.

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?

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

Thanks for your help :slight_smile: Now it works!