Wednesday, October 31, 2012

GAMS and MsgBox

It is remarkably difficult to show a Windows message box in GAMS and react on it at execution time:

$onecho > q.vbs
Select Case MsgBox("No data for ID=" & WScript.Arguments.Item(0) & " Continue?",4,"Database Error")

Case vbYes
   
returnValue = 1
Case vbNo
   
returnValue = 0
End Select
WScript.Quit(returnValue)
$offecho


set
  errorID(*) 
'dynamic set with error IDs'
;

* assume we have an error
errorID(
'myErrorId') = yes;

scalars

   rc
'return code' /0/
   first
/1/
;


* I don't want to put out anything, but this $%!%@$$#! put_utility requires it
file dummy /xx/;
put
dummy;

loop
(errorID$first,
  
put_utility 'exec' / 'cscript //nologo q.vbs '
errorID.tl;
   rc = ErrorLevel;
   first=0;
);


display
rc;

I always cringe when I need to use this dreaded put_utility.

Background: in theory database systems can be designed such that data is always consistent. In practice almost all databases contain data problems. Somehow when doing optimization models we hit these errors more often than other db applications. This code is related to a larger model where we need to react on detecting some form of db error, i.e. stop or try to fix and continue.

image

1 comment:

  1. "Somehow when doing optimization models we hit these errors more often than other db applications." Or perhaps we are just more likely to recognize them as errors?

    ReplyDelete