Friday, February 15, 2013

Checking if program is running in a interactive environment

        I had a class object that used MSGBOX to display an error message.  I ran into a situation where this routine was used in a Web application, and when the error was encountered, it had no where to display the message, because it was running on a server and not on the desktop.
     So, I could have just let the system generate the exception, but this would cause problems with other programs that already had been written and did not have the necessary logic to trap the error. So, I found there is an environment variable that can be checked to determine if the program is running in an interactive state. If it is running in an interactive state, you can use the MSGBOX function. And, if it not running in an interactive environment, you can let the object generate an exception

This is the variable to check:
Environment.UserInteractive



If Environment.UserInteractive Then
msgbox("ERROR")
else
   throw ex
end if