Pressing the [Edit] or [+] buttons on the macros palette, or double-clicking on a line in a list of macros in the Data Manager brings up the macro entry window.
Here, you should define a unique code for the macro by which it can later be found when viewing. Enterprise 6 offers no default (other than ‘Untitled’) for this code so that the codes can be meaningful to each user. You can assign a full Name, further describing the macro.
The number of macros used can grow very rapidly. If they were stored on a hard disk, they would be organised using folders or directories. The macro Group field is provided to help with this purpose. The field has a Lists lookup table, that you can add to in the Data Manager or directly if you have ‘Data Manager Additions’ access. The field can be searched on in both the Quick Find and More Choices windows.
A Keyboard Function Key number can be assigned to a macro. Simply type a number between 1 and 15 in the Play on F Key field - don’t press the Function Key itself. Subsequently, this macro will automatically Play when that Function Key is pressed.
As an option, you can assign a person’s initials to the macro, so that different users can have personalised versions of the Function Key macros. macros without a Person assigned will be Played for everyone without their own specific F Key definitions.
You can also type an “S” for Startup in the Play on F Key field, which will ensure the macro is played each time Enterprise 6 is launched or the ‘Change Access’ function is used. You can allocate more than one S, and can make use of an “S1”, “S2”, “S3” etc sequence if you need them to be Played in a specific order. A second or subsequent macro will not start until you have closed all windows to do with the first or previous. Note that any macros allocated to play on Startup that do not have any Person defined will be Played for all people who have access to macros but do not themselves have any S’s defined. Meanwhile, people that do have their own S’s defined will not also Play the general macros. If you /<Alt>-Click the [OK] button (but not /) in the ‘Who are you?’ window, the Startup macros are disabled.
To aid with the editing of the macro text, three pop-up menus are provided. That on the right provides a list of macro Commands from which the appropriate one can be chosen. Enterprise 6 contains its own macro language and the avaialble commands are listed here. Although not listed, you can also include any 4th Dimension command in your macro. The other pop-ups provide methods by which Enterprise 6 Files and Fields can be included in your macro with the correct name and spelling.
There are two radio buttons, ‘Same Process’ or ‘New Process’. The default is to ‘New Process’. If you click on ‘Same Process’, then this macro will be run in the process currently on screen. This has important implications, which are discussed below. Note that if there is no process currently open when a ‘Same Process’ macro is played, Enterprise 6 will open a new process in which it will attempt to play the macro, but this attempt may not be successful. When using the macro command from within one macro to call another, if the macro being called has the ‘Same Process’ option on, then it can use the same variables and records set by the calling macro.
Using New Process macros effectively makes all variables ‘local’, and loses all record selections. It is therefore possible to make macro ‘utilities’ or ‘functions’ that will be used many times, called by other macros. Note, though, that the called ‘New Process’ macro cannot return values to the calling macro.
‘Same Process’ macros are also extremely useful when called from input or list layouts by pressing a function key or <Command-Shift-M>/<control-Shift-M>, or from Forms, Reports and the [√] button (see below). You can allocate a macro to a File using the Applicable to File pop-up menu, or you can choose to leave the File ‘Unspecified’ by choosing the item at the top of the list. ‘Same Process’ macros will usually be relevant only to one File, and will almost certainly not work if called from another File because they will probably refer to data in their relevant File.
You can also allocate a ‘New Process’ macro to a given File -even if only for the convenience of subsequently finding it. For example, a macro that launches a ‘View Companies’ Process and lists all new Customers could obviously be allocated to Companies, although it could in fact be launched at any time from anywhere in the system.
The check box ‘Play in Background’ can only be turned on if you have already placed an S in the Startup macros field, and if the ‘New Process’ radio button is chosen. Its purpose is specifically related to Startup macros: it allows you to write your own version of a background ‘Process Manager’ procedure. Enterprise 6 already has its own example of one of these: the optional process that checks for Diary Messages and for macros To Do in the Diary. The macros Background Process is not cancellable other than by Quitting Enterprise 6 or by its own programming; it will not cause a ‘Resume’ message when you try to Quit; it does not appear in the Process list; and it does not prevent other macros from being run at the same time. It is only ever useful if the main macro text is encased in a While loop.
The following simple example is a rather annoying Startup macro that will keep on giving a message every three seconds until you Quit Enterprise 6:
While (1=1)
Alert ("This is annoying")
DELAY PROCESS (Current process;180)
End while
More usefully, you could include periodic queries on particular files to see if given criteria have been met, and then perhaps launch another macro that takes action accordingly. Do remember to use the DELAY PROCESS 4D command, because otherwise this Background macro will take up a significant proportion of your computer’s processing time.
As another, more useful example, the following will check at 5 pm each day how many Sales Orders have been entered during the day, and will add the result as a Message into the Diary of a specific person:
mDate:=Current Date
While (1=1)
If ((Current time >=17:00:00) & (mDate= Current Date))
SEARCH ([ORDERS];[ORDERS]Order Date= mDate)
If (Records in selection ([ORDERS])>0)
READ WRITE ([DIARY])
CREATE RECORD ([DIARY])
Dry Code `Allocates a unique no to the new Diary record
[DIARY]Date Do:=mDate
[DIARY]Person:="RAN" `Substitute appropriate initials here
[DIARY]Company Code:= "USERCO" `Assumes your own Company is known to Enterprise 6 with a Company Code of ‘USERCO’
[DIARY]Action Code:= ◊MessAct
[DIARY]Action Desc:= "Orders today: "+String (Records in selection ([ORDERS]))
Diary PersPrior `Necessary to get To Do queries to work
SAVE RECORD ([DIARY])
UNLOAD RECORD ([DIARY])
READ ONLY ([DIARY])
End if
mDate:=mDate+1
End if `Then add other checks
DELAY PROCESS (Current process;3600) `Every minute
End while
Find ... (command-f or control-f)
Use this function to Find a certain text string in the macro text. It will remember what was last searched for, or will pick up any word or phrase currently highlighted in the text. The searching is done from the current cursor position onwards. The first found example is highlighted for manual editing.
Find Next (command-g or control-g)
This finds the next occurrence of the text string last specified in the ‘Find…’ or ‘Replace…’ dialogue boxes.
Replace ... (command-r or control-r)
This brings up a dialogue box with a field for the text string to be found and another for its replacement. The [Replace] button replaces the first instance found after the current cursor position (including the current highlight if that represents the text string to be found), and places the cursor after the last character of the replacement made. This window features a [Replace All] (<Command-r>/
) button, which changes all instances from the current cursor position onwards. Replace Next (command-t or control-t)
This replaces the next occurrence of the text string to be found with the new text specified.
Calculate Indents (command-i or control-i)
This function can be called periodically to make macros that contain many If and Case statements and While loops more legible. Errors such as an incorrect number of End ifs will be highlighted by the text failing to return neatly to the ‘leftmost’ position at the end.
Edit macro (command-m or control-m)
This function allows you to edit a separate macro to that currently on screen in a new macro window in a new Process. If you highlight a macro Code in the text of a macro and select this function, the macro with that macro Code will appear in the new window. If not, or if you highlighted something that is not a valid macro Code, you will be shown the macros Find window.
Expand Text (command-; or control-;)
This function is used to increase the macro Text field to full screen size for ease of typing. The cursor must be in the macro Text field for the function to operate.
This window has a Functions menu with ‘Find’ and ‘Replace’ facilities.
‘Find…’ (<Command-f>/) allows you to specify what to Find. It will remember what was last searched for, or will pick up any word or phrase currently highlighted in the text. The searching is done from the current cursor position onwards. The first found example is highlighted for manual editing.
‘Find Next’ (<Command-g>/) finds the next occurrence of the text string last specified in the ‘Find…’ or ‘Replace…’ dialogue box.
‘Replace…’ (<Command-r>/) shows a window with a field for the text string to be found and another for its replacement. The [Replace] button replaces the first instance found after the current cursor position (including the current highlight if that represents the text to be found), and places the cursor after the last character of the replacement made.
The window features a [Replace All] (<Command-A>/) button, which changes all instances from the current cursor position onwards.
‘Replace Next’ (<Command-t>/) replaces the next occurrence of the text string to be found.
To revert to the normal screen, click [√] if you wish to save the changes you have made to the text, or [X] if you do not.