At 10:40 AM 3/6/2010, Jim Belisle wrote:
I have never used the SET ERROR VAR code before and would like to
verify I understand the explanation in the Help.
Jim,
A well written R:BASE program need to be able to check and determine
if key lines are executed or the proper answers are given -- and, if
not, then display an error message or run alternative commands.
R:BASE has three different ways to check the code for proper
execution. The three ways you can process R:BASE errors in your
application code are: the R:BASE ERROR VARIABLE, SQLCODE, and the
WHENEVER statement.
R:BASE ERROR VARIABLE
The first, and most commonly used, is the ERROR VARIABLE. The
ERROR VARIABLE is a special variable defined to hold the error
codes that R:BASE returns. The first step in using the error
variable is to define the name of the variable.
Use the command: SET ERROR VARIABLE ErrorVar, where ErrorVar is
the name of the variable that contains the error code. You can
name the error variable any name you want. The error variable
has a value after every command in a program or R:BASE session.
The value is either 0 (successful command) or a number indicating
the error that occurred on the last executed command.
Because the R:BASE error variable is set after every command,
when checking the errorcode the very next line after the command
to be checked must test the error variable or place its value
into a holding variable: SET VARIABLE vhold =.errorvar. The
variable vhold is then used to determine what happens next in
the program.
There is only one error variable in a program (errorvar), but
there can be many holding variables (vhold). Holding variables
are needed because the error variable is set after every command.
For example, PAUSE is a command that always executes successfully,
so the error variable is always set to 0 after it.
To turn off an error variable or to use one with a different name
you must use the SET ERROR VARIABLE OFF command. When using an
error variable do not clear it with the CLEAR VAR command. When
clearing variables always use the CLEAR ALL VAR EXCEPT errorvar.
You can generate other errors in your application by clearing an
error variable instead of setting it off.
Error codes trapped by the error variable are not only for SQL
commands, but any command that can be used in R:BASE. This is
different from the other techniques as they only check the
commands that are SQL specific.
A useful technique in identifying errors in the code is to place
an IF statement based on the holding variable to redirect the
flow of the code and to provide a message to the user. For
example:
SET ERROR VARIABLE vError
CONNECT RRBYW16 IDENTIFIED BY NONE
-- SHOW ERROR vError command will display the R:BASE message
SET VAR vHold = .vError
IF vHold <> 0 THEN
CLS
PAUSE 2 USING 'Error Connecting Database.' +
CAPTION ' Running R:BASE Your Way!' +
ICON STOP +
BUTTON 'Press any key to continue ...' +
OPTION MESSAGE_FONT_COLOR RED +
|MESSAGE_FONT_NAME VERDANA +
|MESSAGE_FONT_SIZE 11 +
|MESSAGE_FONT_BOLD OFF +
|BUTTON_COLOR WHITE +
|BUTTON_FONT_COLOR GREEN +
|THEMENAME Vista CG
RETURN
ENDIF
Important Notes:
. Any successful command will always set the value to 0.
. Use SET ERROR VARIABLE OFF to turn off the process.
. Only one error variable is used in an R:BASE session.
An R:BASE session is from when you start R:BASE until
you EXIT.
Hope that helps!
Very Best R:egards,
Razzak.
--- RBASE-L
================================================
TO POST A MESSAGE TO ALL MEMBERS:
Send a plain text email to [email protected]
(Don't use any of these words as your Subject:
INTRO, SUBSCRIBE, UNSUBSCRIBE, SEARCH,
REMOVE, SUSPEND, RESUME, DIGEST, RESEND, HELP)
================================================
TO SEE MESSAGE POSTING GUIDELINES:
Send a plain text email to [email protected]
In the message SUBJECT, put just one word: INTRO
================================================
TO UNSUBSCRIBE:
Send a plain text email to [email protected]
In the message SUBJECT, put just one word: UNSUBSCRIBE
================================================
TO SEARCH ARCHIVES:
Send a plain text email to [email protected]
In the message SUBJECT, put just one word: SEARCH-n
(where n is the number of days). In the message body,
place any
text to search for.
================================================