A2. Wizard Code Segments

Contents

Explanation of Code Segments.
Explanation of each Code Segment type.
   Common Time
   Entry Time
   New Item
   Old Item
   Command Time
   Acceptance Prompt
   File Time
   Delete Time
   Exit Time
   User Defined
   Display Time
   Before Field
   Input Conversion
   Output Conversion
   After Input
   After Field
Wizard Screen sequence of operation.
Code Segments in Wizard Reports.
Wizard "language" statements.
Wizard program variables and their use.
Code Segment programming hints.
Wizard user-extensible templates.

Explanation of Code Segments.

Code Segments are used to handle Wizard program requirements that are not handled by the standard Wizard features. Each Code Segment may contain standard BASIC statements as well as special Wizard language statements.

Code Segments are added to a Wizard program definition by using the EC Command. When the program is generated, the Code Segments are automatically added to the program as internal (GOSUB) subroutines. Each Code Segment is executed at a particular time during the running of a Wizard program (depending on the Code Segment Type).

Since the Code Segments are internal subroutines, they can access all the variables used in the generated program. This allows tremendous flexibility as well as fast (run-time) speed. Some knowledge of BASIC is necessary to use the Code Segment feature.

The Code Segment feature makes it possible for the application designer to create complete, efficient applications with a minimum amount of programming.

Code Segment Types

There are sixteen (16) Code Segments. That is, they are related to the entire Wizard program being created. There are five Field Code Segment and these are related to each individual Field Definition and they are called Field Related. The other eleven are Global Code Segment types.

For each Wizard Screen or Report program, you may use one of each of the Global Code Segments. For each Field Definition within the Wizard program, you may use one of each of the Field Code Segments.

Note not all Code Segments are the same in Wizard Reports.

Editing Code Segments

Wizard provides several commands which allow you to maintain code segments. These all operate from the main command prompt of the Screen Formatter They are:

ECEdit code for a field, both Global and Field Code Segments. If the command is not followed by a field number, you will be asked to move the cursor to the field whose code you wish to edit. (Full Screen)
ECGEdit the Global Code Segments. (Opens a Window)
ECFEdit the Field Code Segments, works the same as the EC command (Opens a Window)
EBIDisplays the first line of all Before Field code segments for the screen and allows you to edit them. (Opens a Window)
EICDisplays all Input Conversion code segments. (Opens a Window)
EOCDisplays all Output Conversion code segments. (Opens a Window)
EAIDisplays all After Input code segments. (Opens a Window)
EAFDisplays all After Field code segments. (Opens a Window)

All these options allow you to edit the code by selecting the appropriate line number.

When painting a Wizard data entry Screen the EC Command will show the following Screen:

When painting a Wizard Report the EC Command will show the following Screen:

Explanation of each Code Segment type.

Common Time

Common Time is a Global Code Segment and can be used in both Wizard Screens and Reports.

Sometimes you may want to share data between programs without having to write the data and then read it in the next program, or without having to pass it as a parameter to a subroutine (which takes more memory). This may often be achieved by using the BASIC COMMON statement. (For more information on the way COMMON works, refer to your system's BASIC manual.)

Common time is executed immediately after the Wizard common and is the first Code Segment in the Wizard screen Although you may put code here, you would usually only want to put common statements in here.

Note that no Wizard variables have been assigned at this time.

Entry Time

Entry Time is a Global Code Segment and can be used in Wizard Screens or Reports.

It is executed only once after a Wizard program is entered (starts running). All Wizard Screen variables have been assigned, files opened and the Screen has not been painted as yet.

This is the place that you could do your own user Security checks or read control type records and/or setting default variables.

Entry Time is After :
Wizard Assigns all variables and opens all files.

Entry Time is Before:
Wizard paints the Screen and asks for input into the First Field. (i.e. Before the Before Field Code Segment.)

Entry Time Example: Custom Function Keys

It is possible to reprogram the function keys for specific Wizard screens. A good place to do this is in the Entry Time Code Segment. Wizard will have already read the default definitions for function keys into a dimensioned array named func(). This array has 24 elements, 1-12 for the unshifted function keys, and 13-24 for the shifted function keys.

The following sample code will set function key 3 to enter the string "//CUST" which would cause the Jump-time command "//CUST" to be executed when <F3> is pressed:

   001: func(3) = "//CUST"

New Item

New Item is a Global Code Segment and can only be used in Wizard Screens

When a Wizard Screen is running, the data entry operator will enter an item-id to select an item. Wizard then determines if the item is an old item (already exists), or a new item (does not exist yet).

If the item is a new item, then the Wizard variable NEWITEMFLAG is set to 1 and then the New Item Code Segment is executed.

This is a good place to set default values for fields.

New Item is After :
User input into the Id field.

Command Time Code.

Input Conversion Time Code.

Wizard reads from the Major File and finds that this is a New Item.

New Item is Before:
Output Conversion Time Code.

After Input Time Code.

Old Item

Old Item is a Global Code Segment and can only be used in Wizard Screens

When a Wizard Screen is running, the data entry operator will enter an item-id to select the next item. Wizard then determines if the item is an old item (already exists), or a new item (does not exist yet). If the item is an old item, then the Wizard variable NEWITEMFLAG is set to 0 and then the Old Item Code Segment is executed.

This is a good place to check if the Item is valid or not.

When a Wizard screen encounters a new item, the program prompts the user for each of the fields on the screen. If it is an old item, Wizard displays the item and moves input to the Acceptance Prompt. If you want to force Wizard to move through the fields of an old item you simply fool Wizard into thinking that the item is a new item with the code:

   NEWITEMFLAG=1

In the Old Item code segment.

Old Item is After :
User input into the Id field.

Command Time Code.

Input Conversion Time Code.

Wizard reads from the Major File and finds that this is an Old Item.

Old Item is Before:
Wizard prints all the Field Pictures on the Screen.

Output Conversion Time Code.

After Input Time Code.

Command Time

Command Time is a Global Code Segment and can only be used in Wizard Screens.

The Command Time Code Segment is executed immediately after any input is entered at any Wizard Screen field.

This is a good place to intercept Wizard Commands and/or create your own Commands.

Command Time is After :
User input into any Field. (Not Acceptance Prompt)

Command Time is Before:
Wizard Commands are executed, (if the user enters a Wizard Command)

Input Conversion Time Code.

Acceptance Prompt

The Acceptance Prompt is a Global Code Segment and can only be used in Wizard Screens.

It is executed immediately after the data entry operator enters data at the Acceptance Prompt

This is similar to Command Time.

Acceptance Prompt Time is After :
The user enters any data at the Acceptance Prompt.

Acceptance Prompt Time is Before:
Before Field Code. If the user entered a Field number, hit the <Esc> or <F10> key.

File Time Code, if the user just hit the enter key.

Delete Time Code, if the user entered the Delete command FD.

File Time

File Time is a Global Code Segment and can only be used in Wizard Screens.

In a Wizard Screen the File Time Code Segment is executed immediately before the Wizard Screen files the Main or Major and any Linked items that have changed.

This is a good place to check the integrity of the Items about to be filed or to update any control records.

File Time Code is After :
Acceptance Prompt Code

Wizard checks that there is data in all of the Mandatory fields

File Time Code is Before:
Wizard Files all Items that have changed.

Delete Time

Delete Time is a Global Code Segment and can only be used in Wizard Screens

The delete time Code Segment is executed just after the data entry operator enters an FD command at the Acceptance Prompt, and just before the data item is deleted.

This is a good place to check if the given user is allowed to delete the current item and/or update control records.

Delete Time is After :
Entry of FD at Acceptance Prompt

Acceptance Prompt Code.

Delete Time is Before:
Wizard Deletes the Main or Major items.

Delete Time Note:

Wizard will not delete Linked items!

Exit Time

Exit Time is a Global Code Segment and can be used in both Wizard Screens or Reports.

In a Wizard Screen or Report, the Exit Time Code Segment is executed only once, immediately before the Wizard program is exited.

This is a good place to handle processing that needs to be done just once when a Wizard program is exited. For example, saving "batch totals".

Exit Time Code is After :
The user hits <Esc> or <F10> when at the First Field in the Screen.

File or Delete time if the Wizard variable ID.SOURCE is set to 2.

The user enters <Esc> or <F10> when at Acceptance Prompt and the Wizard variable ID.SOURCE is set to 2.

Exit Time Code is Before:
The Screen Exited.

User Defined

User Defined is a Global Code Segment and can be used in both Wizard Screens or Reports.

Unlike the other Code Segments the User Defined Code Segment is not automatically executed and is a good place to put Code which is required more than once, or code that is more than 5 to 10 lines long.

Instead, you use it to hold one or more local subroutines (the object of a GOSUB statement). These local subroutines are executed by the use of GOSUB statements in other Code Segments.

To prevent statement number conflicts within the Wizard generated program, you can use only numeric labels from 101 to 299 or 1000000 to 2999999. You may also use any alphanumeric labels.

User Defined Code is After :
A GOSUB statement in other Code Segments

User Defined Code is Before:
The statements following the GOSUB above.

Display Time

Display Time is a Global Code Segment and can only be used in Wizard Screens

When a Wizard screen is generated it automatically paints the screen for you. Sometimes, however, you may wish to add your own display "hacks" to the screen. This can be done using the Display Time code segment. This code segment is executed each time the screen is refreshed prior to the painting of the fields. (This way, if you have inadvertently displayed something where some of the data for the screen appears, that data will display as a priority.)

Display Time is After :
Wizard is told to Paint the Screen.

The Screen has been Painted and the Wizard variable BEFORE.PRINT is set to 0.

Display Time is Before:
The Screen is Painted.

Before Field

Before Field is a Field Code Segment and can only be used in Wizard Screens.

You can have one Before Field Code Segment for each Field. It is executed just before the data entry operator is prompted for input. This a good place to Skip the current Field.

Before Field Code is After :
Wizard has loaded all the Field related data, like AMC,VMC,ITEMNUM, etc.

Before Field Code is Before:
Default data loaded.

User input for a given Field.

Input Conversion

Input Conversion is a Field Code Segment and is only used in Wizard Screens.

Each Wizard field can have an Input Conversion code segment Typically, you would use an Input Conversion code segment to validate the user's data input into a field. This code segment is executed after Wizard has executed its own input validation.

Input Conversion Code is After :
User input.

Command Time Code.

Wizard's input conversions.

Input Conversion Code is Before:
The data input by the user is loaded into the current item.

Output Conversion Code.

After Input Code.

Output Conversion

Output Conversion is a Field Code Segment and is only used in Wizard Screens.

Each field on a Wizard screen may have an Output Conversion code segment The Output Conversion code should generally be used to convert data from an internal format (i.e., how it is to be stored on the file) to the format in which it shall be displayed. In this respect it is the reverse of the Input Conversion

Output Conversion Code is After :
Input Conversion Code

Output Conversion Code is Before:
After Input Code.

Data for a field is printed on the Screen.

The data for the current Field is Printed on the Screen. Therefore, it is also before Before Input, as the data about to be prompted for is printed on the Screen.

After Input

After Input is a Field Code Segment and is only used in Wizard Screens It is executed immediately after the data value for the field is displayed and is executed only if data is entered into the Wizard field by the data entry operator. This is a good place to check whether or not you need to Skip subsequent Fields.

After Input Code is After:
Output Conversion Code.

The data is printed on the Screen.

After Input Code is Before:
After Field Code.

After Field

After Field is a Field Code Segment and can only be used in Wizard Screens It is executed immediately after the After Input Code Segment and it is executed whether the operator enters data or simply presses the <Return> key.

After Field Code is After:
After Input Code, or

After the operator presses the <Return> key.

After Field Code is Before:
Before Field Code for the next Field or Acceptance prompt

Wizard Screen sequence of operation.

It is important to know the Sequence of Operation of a Wizard data entry program in order to decide which kind of code segment should be used for a particular task, and to debug a code segment if it is not doing what you want. A Code Segment is a section of the Screen Code that Wizard will GOSUB to, only if you have placed Basic Code in the given Segment.

The Sequence of Operation is as follows:

200000Entry Time CS
100000The data labels and text fields are printed on the screen.
220000Display Time CS
2000Input Processing Loop for each field.
380000Default specification.
400000Before Fields CS
 If FIELDMODE = D (Display Only), then no more processing is done for this field, RETURN from subroutine 2000.
 If FIELDMODE = I (Input Once) and data existed in the field then no more processing, RETURN from subroutine 2000.
WInputOperator prompted for input, stored in I$ and WCOM.
800000Command Time CS
2100If a command has been entered, the command is executed.
If the data entered is a <Return> (null), then GOSUB 2020, at which:
2020The Mandatory specification is checked. If this field is a mandatory and there is no data already in this field then, the operator is prompted again for data entry.
The Skip if no data specification is checked and SKIPNUM is reset, no more processing for the field is done.
If a data value has been entered, then:
2500The validation specification is performed on the data entered.
450000Input Conversion CS
50000If this field is an Item-id field, then the data value is used as an Item-id to read the Item from the file.
250000If the Item does not exist, the New Item CS is executed.
260000If the Item exists, the Old Item CS is executed.
The Item-id is stored in the array INPUT.IDS(ITEMNUM).
If the data value is not an Item-id, then the data value is stored in the array INPUT.ITEMS(ITEMNUM). ITEMNUM contains the item number of the current Wizard field.
37000
38000
38100
One or more data values are redisplayed on the screen, depending on what was just entered.
550000During the display of data values, the Output Conversion CS is executed once just before each data value is displayed. Calculation specifications, if they exist, are executed at the beginning of the Output Conversion CS.
500000After Input CS
600000After Field CS. This code segment is not executed if a command is entered that begins with / or ?.
The variable CF is incremented by the variable SKIPNUM to determine the next field to be processed. SKIPNUM is usually set to 1.
Processing begins on the next field until all fields are done.
2200Acceptance Prompt
 The Acceptance Prompt message is displayed.
14000File the item: Wizard will check all Mandatory fields to see that they contain data.
900000File Time CS
15000Delete the item
950000Exit Time CS

The User Defined code segment is comprised of one or more local subroutines, each of which you will label with a statement number. The statement number is selected by the designer. The User Defined routines are executed only from other code segments They are executed as the result of a GOSUB statement from a given code segment.

Code Segments in Wizard Reports.

Only some types of Code Segments may be used in Wizard Reports and the Code Segments are executed only if they exist.

Global Report Code Segments

  1. The Entry Time CS is executed first in a Wizard Report.
  2. The After Read CS (equivalent to Old Item in Wizard Screens) is executed after each item is read. Each data item is initially read into INPUT.ITEMS(1).
  3. The User Defined Code Segment is not directly executed. Instead, it holds local subroutines that are executed by GOSUB statements in other Code Segments.
  4. The Exit Time CS is executed last.

Field Related Report Code Segment

The Before Print CS (equivalent to Before Field in Wizard Screens), is executed just before the specified Wizard field is printed.

Wizard "language" statements.

Wizard language statements are an extension of PICK/BASIC.

Important Note: All Wizard language statements must begin with a # (number sign, sometimes called pound or hash) in the first column of the code line.

Field Names In Assignment Statements

If EXTENSION, UNITCOST, and QUANTITY are fieldnames in a Screen or Report then the following Code Segment:

   # EXTENSION = UNITCOST * QUANTITY

will multiply the current contents of the UNITCOST field by the current contents of the QUANTITY field and store the result in the EXTENSION field.

THE DISPLAY STATEMENT

The following Code Segment:

   # DISPLAY EXTENSION

will update the display of the field called EXTENSION.

THE TOTAL FUNCTION

The following Code Segment:

   # CHECK.TOTAL = TOTAL(CHECK.DEBIT.V)

will sum the values of the multi-value field CHECK.DEBIT.V and store the result in the CHECK.TOTAL field. Note that most totals are done as a Derived Calculation by using the E Command.

Wizard program variables and their use.

When writing Code Segments, you will probably want to access some of the variables that are used in a Wizard program We have included here the variables that are most commonly used in Code Segments. Most of these variables are used in the Code Segment examples that follow.

You can learn more about the Wizard variables by studying the Wizard generated programs. They are stored in file W2 (unless you have specified another Program File with the EG command). Each Wizard generated program name is preceded by the characters "W.", so if you named your program EPROSPECTS, you can examine it by typing ED W2 W.EPROSPECTS.

You may generate a Wizard Data Entry Screen with comments by using the EF command However, be careful not to exceed the item size.

MAT INPUT.IDS
This variable contains the item-ids (keys) of the items (records) that are being accessed by your Wizard program. One Wizard program can retrieve and/or update data from many items. For each element of INPUT.IDS there is always a corresponding element of MAT INPUT.ITEMS.

MAT INPUT.ITEMS
This contains the items (without the item-ids) that your Wizard program is accessing.

MAT DIRTY
This variable contains a flag for each element of INPUT.ITEMS. If the flag is 0, then no data has been entered into that item. If the flag is greater than 0, then the flag is a number (e.g. 1) which specifies the element number of INPUT.FVS which contains the corresponding file variable.

MAT INPUT.FVS
This contains the file variables of the files. In simple programs, there is one element of INPUT.FVS for each element of INPUT.ITEMS. However, there may be one element of INPUT.FVS for several elements of INPUT.ITEMS. This occurs when a field in a Line Item Set has a link specification.

COMLOC
This contains @(0,22):EOL, which is the location where command messages are typically printed, concatenated with an EOL character (Erase to end Of Line). The EOL character erases any previous command message.

ErrLoc
This contains @(0,23):EOL, which is the location where error messages are typically printed, concatenated with an EOL character (Erase to end Of Line). The EOL character erases any previous error message.

I$
This contains the current input immediately after it has been entered by the data entry operator.

WCOM
This contains a copy of I$ that has been capitalised by calling the external subroutine WizLowerUpper() which will convert lower case to upper case and will convert /EX, <F10> (function key 10) and <Esc> to Exit. WCOM is used to test the current input of the data entry operator to see if it is a command (which can be upper or lower case).

ITEMNUM
This contains the item number of the current Wizard field. ITEMNUM is used as an index into INPUT.IDS and INPUT.ITEMS. So, when a Wizard program is running, INPUT.IDS(ITEMNUM) contains the item-id associated with the current Wizard field And INPUT.ITEMS(ITEMNUM) contains the item (without the item-id) associated with the current Wizard field. The current Wizard field means the field at which the cursor is positioned.

AMC
This contains the attribute number of the current data value. The current data value means the data value at which the cursor is positioned.

VMC
This contains the value number of the current data value.

SVMC
This contain the secondary value number of the current data value.

SKIPNUM
This contains the number of Wizard fields to skip to get to the next Wizard field.

For example, if the statement SKIPNUM=4 is executed in a code segment then the next Wizard field (for which your Wizard screen will request data) will be the 4th field after the current field.

If the statement SKIPNUM=0 is executed in a code segment then your Wizard Screen will request data again for the current field. You use this to stay at a particular field when your code segment has detected a data entry operator error.

Note: SKIPNUM is always = 0 at Before Field CS, thus if SKIPNUM is set to not equal 0 then that will be the number of fields skipped.

Note: SKIPNUM can be set to +ve or -ve values thus if SKIPNUM is set to -1 then the previous field will be the next field.

ERR
This contains a flag that signals to erase the error location line at 23. So if the statement ERR=1 is executed in a code segment, then the error message line 23 will be erased just after you enter data in the current field.

ERRMSG
This variable is used to load your Error Message that will be printed in the Acceptance Prompt location. You may have two lines of Error Message with a maximum of 77 characters per line. You must then GOTO 2111 which will print ERRMSG and request Wizard to re-prompt the current field. So, for example:

   ERRMSG='Your message'
   GOTO 2111

or

   ERRMSG<1>='Your message line 1'
   ERRMSG<2>='Your message line 2'
   GOTO 2111

MSGSTALL
This is used in conjunction with ERRMSG above, and if set to 1 will require the operator to Hit any key to continue after the ERRMSG is displayed before Wizard will re-prompt the current field.

Msg
This variable can be loaded in the same way as ERRMSG above and when loaded with your Message you then GOSUB 3000 at label 3000 Wizard will display the Msg.

Code Segment programming hints.

Here are some programming hints for Wizard screens:

Wizard user-extensible templates.

Code Segments allow you to change the PICK-BASIC code that Wizard generates for one program. However, Wizard also allows you to change the code that Wizard generates for all programs.

Warning: If you change these templates you will cause problems when you upgrade to a newer version of Wizard because your changes will not automatically be copied to the new templates, and the old ones will be out of date. If you do want to change these templates, be sure to document the changes carefully!

Templates For Data Entry Screens

In the WUTIL file, you will find items called DMAIN1 and DMAIN2. These are the Wizard data entry screen templates. They contain most of the code that is generated in every Wizard data entry screen

To change the code that Wizard generates for all data entry screens, change DMAIN1 or DMAIN2. For instance, let us say that you wanted to change the exit command from <Esc> to X. You would change all references to the Exit variable in DMAIN1 and DMAIN2 to X.

If you wanted to add a new field command, you would probably add the code to subroutine 2100 in DMAIN1, where all Wizard field commands that start with / or ? are processed.

If you wanted to add a new Acceptance Prompt command, you would add the code to routine 2200 in DMAIN1, where all Wizard Acceptance Prompt commands are processed.

If you want to delete a command, it is probably a good idea to comment out the code rather than actually delete it. You might change your mind. Put the comment asterisks after the first seven characters in the lines that you want to comment out. These characters are the features specification (see discussion below).

Templates For Reports

In the WUTIL file, you will find items called RMAIN1 and RMAIN2. These are the Wizard report templates. They contain only a small percentage of the code that is generated in Wizard reports.

However, RMAIN1 can be changed just like DMAIN1 or DMAIN2. RMAIN2 only contains a date and can be ignored.

Template Features Specification

The first seven characters that are at the beginning of every line in the templates are called the features specification. They tell the generator when to include the template line of code in a program that is being generated.

For instance, if a line of code in DMAIN1 starts with _______, that line of code is included in every Wizard data entry screen that is generated.

If a line of code in DMAIN1 starts with _03____, that line of code is included in every Wizard data entry screen that has feature 3 turned on.

If a line of code in DMAIN1 starts with _03&_69, that line of code is included in every Wizard data entry screen that has feature 3 and feature 69 turned on.

The format for this code is as follows. It must match the template nnnsmmm where:

nnnThis is a feature number preceded by either _ (which is ignored) or ~ (tilde), which tells the Wizard generator process that this line is to be included if this feature is not on. So ~61 is the opposite of _61.
sThis is a sign - it can be either & or !. & means that the first and second feature numbers must both be selected, whereas ! means that either the first or second feature can be present for this line of code to be included.
mmmThis is a second feature number. The format of this is the same as that of the first (see under nnn above).

If you are only going to change or comment out lines in the templates, then you do not need to know anything about the features specification. If you are going to add lines of code to the templates, you can start every line with _______.

For the really technically minded: the first 20 or so template features are controlled by the user defined features of the EF command (Edit Features) in Custom Wizard. Feature 3 in the EF command happens to be feature 3 in the templates, but do not count on this correlation being maintained throughout the screen. The other template features are automatically turned on when various capabilities of Wizard are used. For instance, feature 61 is turned on if any Line Item Sets are specified.

Example: A Custom Heading For All Of Your Wizard Screens

Let us say that you would like to add a customised heading to all of your Wizard Screens. Do the following:

You edit WUTIL DMAIN2. At the bottom of this item is the subroutine 100000 which displays the screen picture for Wizard Screens. At the top of this routine you can add the line:

   _______   PRINT @(0,0):TIMEDATE():

or whatever you would want as the heading for all your screens. Note that to implement any changes to the templates you will need to regenerate all the Wizard screens.

This could be achieved on an individual screen basis using the Display Time Code Segment.

Note that instead of using a fixed text string for your Company Name, you could use a READ statement to read in some text from an item in a file. This would make it possible to have different text on different accounts.