Feedback if GAMS code has been executed successfully Topic is solved

Questions on using the GAMS APIs (Python, .NET, etc.)
Post Reply
Janisch
User
User
Posts: 26
Joined: 2 months ago

Feedback if GAMS code has been executed successfully

Post by Janisch » 2 weeks ago

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

Janisch
User
User
Posts: 26
Joined: 2 months ago

Re: Feedback if GAMS code has been executed successfully

Post by Janisch » 1 week ago

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?

User avatar
bussieck
Moderator
Moderator
Posts: 534
Joined: 4 years ago

Re: Feedback if GAMS code has been executed successfully

Post by bussieck » 1 week ago

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

Janisch
User
User
Posts: 26
Joined: 2 months ago

Re: Feedback if GAMS code has been executed successfully

Post by Janisch » 1 week ago

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?

User avatar
bussieck
Moderator
Moderator
Posts: 534
Joined: 4 years ago

Re: Feedback if GAMS code has been executed successfully

Post by bussieck » 1 week ago

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

Janisch
User
User
Posts: 26
Joined: 2 months ago

Re: Feedback if GAMS code has been executed successfully

Post by Janisch » 1 week ago

Thanks for your help :) Now it works!

Post Reply