Using and Customizing your Program

urcorner.gif (122 bytes)
llcorner.gif (121 bytes) lrcorner.gif (122 bytes)

Back ] Home ] Next ]

This part of the help file is meant to give you a overview of what is going on in your Code Magic program.  We recommend at least reading Section 1 so that you know how to call your program.

Section 1:  Calling your Code Magic program
Section 2:  Program Flow
Section 3:  Available Variables
Section 4:  Available Functions
Section 5:  Available Macros


Section 1:  Calling your Code Magic program

This is the start line of your Code Magic program:

start MyProgramName(ScriptMode, RegisterID, RegAsk)

The program has 3 parameters ScriptMode, RegisterID, and RegAsk.  Here is a explanation of these parameters and their values:

ScriptMode:
ScriptMode controls what mode the program starts up in.
Value Description
A Places the script in Add mode.
D Places the script in Display mode.  This is the default.

RegisterID:
This contains the Register ID that the program will starts up with.

RegAsk:
This controls the program's behavior for handling the Register ID
Value Description
Y Ask for Register, populate with RegisterID or $REGID
N Ask for Register only if RegisterID and $REGID are !DP
X Ask for Register, DO NOT populate with RegisterID or $REGID

 


Section 2:  Program Flow

Code Magic programs flow in this manner:

Variable Init
ê
Register Acquisition
ê
Mode Check
ê
Custom Code:
Before DB Read
ê
Read Once Data Loaded
ê
Main Loop:
If Mode D - Read first layer
If Mode A - Keep going
ê
Custom Code:
After DB Read but Before Form Display
ê
Display Form
ê
Custom Code:
After Form Display but Before DB Write
ê
Button Logic:
Cancel - Confirm then Exit
Add Button - Clear variables and switch to mode A and return to form.
Update Button - If ExecMode N is set switch to mode A without clearing variables otherwise switch to mode U, return to form.
Previous Button - Read previous layer, return to form.
Pull Forward Button - Read top layer and populate variables, return to form.
Remove Button - Confirm, Remove current layer, load previous layer, return to form.
ê
Button Logic Continue:  SUBMIT (Next or Submit)
If mode D - Read next layer, return to display.  If DB Read hits End of DB, prompt for action.
If mode A - Add new layer to record.
If mode U - Update layer.
ê
Custom Code:
After DB Write
ê
Button Logic Continue:  SUBMIT (Next or Submit) Continued
If mode A and ExecMode X is set - switch to mode D and goto top of main loop.
If mode U - switch to mode D, reread current layer, return to form.

Custom Code:
After Program End (Note:  This Custom Code block can only contain functions since main program execution never gets here.)

 


Section 3:  Available Variables

The following variables are declared in all Code Magic programs and may be used by your custom code:

Variable Type Description
AddButtonTextThis variable is assigned to the Add button.
CurLayerText This variable is assigned to the Layer x: button.  It is not used in the program and results in the current layer being redisplayed.
ExecuteModesTextThis contains the string for the execution mode.  See explanation below.
LayerPositionNumeric This contains the number of the current layer.
PrevButtonTextThis variable is assigned to the Previous button.
PullForwardOffBinary This variable will override execute mode F and disable Pull Forward if set to 1.
PullFwdButtonTextThis variable is assigned to the Pull Forward button.
rcNumeric Generic return code variable used by the database functions.  Can be used anywhere.
RegAskTextDetermines if a register is asked for at program start.  This is a startup parameter.
RegisterIDText The register being accessed by the program.  This is a startup parameter.
RemoveButtonTextThis variable is assigned to the Remove button.
ScriptModeText This contains the current running mode.  This is a startup parameter.
UIDs[]NumericThis array stores the UIDs of the record layers.
UpdateButtonText This variable is assigned to the Update button.

 

ExecuteModes:
The ExecurteModes variable contains a string of characters that control what functions are enabled in your program.  If you want to check for the status of a certain mode, use the $find() function on ExecuteModes.
Mode Function
A Add
D Display
F Allow Pull Forward on Add
N Update to New Layer
R Remove
U Update
X Display After Add

 


Section 4:  Available Functions

These functions are available to your custom code in all Code Magic programs:

CMMsgBox
dynamic function CMMsgBox(DialogMessage, DialogTitle, Button1, Button2, Button3) is b
This function is used to display a generic message to the user.  It allows for up to 3 buttons at the bottom of the dialog.  Similar to the MsgBox function in Visual BASIC.
Variable Type Description
DialogMessage Text The message to display to the user.
Dialog Title Text Optional - This is the title of the dialog.  If not specified, defaults to the script name.
Button1 Text Optional - The label for the first button.  If not specified, defaults to Ok.
Button2 Text Optional - The label for the second button.
Button3 Text Optional - The label for the third button.
Return Value Binary Returns 1, 2, or 3 indicating the button that was pushed.

CMInputBox
dynamic function CMInputBox(DialogMessage, VariableIO, DialogTitle, VarLen, VarEdit, ShowEditMsg, Button3) is b
This function is used to ask the user a question and collect the answer.  Similar to the InputBox function in Visual BASIC.  The box has a Ok and Cancel buttons by default.
Variable Type Description
DialogMessage Text The message to display to the user.
VariableIO Variant This is where the answer to the question is returned.  Can be prepopulated.
DialogTitle Text Optional - This is the title of the dialog.  If not specified, defaults to the script name.
VarLen Binary Length of the box for the question input.
VarEdit Text Optional - The MUI edit for the question.  Ex:  "DB``3" for a database 3 lookup.
ShowEditMsg Text Optional - Display a MUI value for the input.  Ex:  Inputting a staff id with a "DB``3" MUI will result in the staff member's name being displayed under the input box.
Button3 Text Optional - The label for the third button.
Return Value Binary Returns 1, 2, or 3 indicating the button that was pushed.  1 = Ok, 2 = Cancel

CMTrapDBError
dynamic function CMTrapDBError(DBID, RegisterID, ErrorCode, BlockID) is n
This function is used to trap errors on the database IO functions.  This will present the user with a message containing the description of the error code and a opportunity to retry errors that are non fatal.  You must check the return from this function and have a goto and label to handle if the user decides to retry the operation.
Variable Type Description
DBID Numeric This is the number of the database the error occurred on.
RegisterID Text This is the register id that the error occurred on.
ErrorCode Numeric This is the return code from the database IO function.
BlockID Text This is a identifier for where in the code the error happened.
Return Value Numeric Returns 1 if the function can be retried and the user selects to do so.  Otherwise returns 0.

 


Section 5:  Available Macros

These macros are available to your custom code in all Code Magic programs.  Code Magic will replace the macros with their appropriate values.  Please note that the macros are case sensitive.

Macro Value
%%DBERRORADDON%%Additional text for use in the database IO error message
%%DBFRIENDLY%% Friendly name for the selected database as specified in the Program Type & Options screen
%%DBID%%Database number as specified in the Program Type & Options screen
%%DIALOGBACK%%HTML color for the message box title background as specified in the Options dialog
%%DIALOGFORE%%HTML color for the message box title foreground as specified in the Options dialog
%%DSTDECLARE%%The DST variable declares
%%EXECMODES%%The Execute Modes string
%%HEADERDST%%The header DST for the record specified for the Read / Write & Read Only group.
%%PROGNAME%%The program's name for the start element.
%%PROGTITLE%%The program's friendly name as specified in the Program Type & Options screen
%%READDST%%A comma delimited list of all DSTs that are used in Read / Write and Read Only groups
%%READONCEDST%%A comma delimited list of all DSTs that are used in the Read Once group
%%WRITEDST%%A comma delimited list of all DSTs that are used in the Read / Write group

©2004 mtlogo.gif (901 bytes) MainTree Systems

urcorner.gif (122 bytes)
llcorner.gif (121 bytes) lrcorner.gif (122 bytes)