You are on page 1of 24

Macros and Events

:
Macros:
A macro is a script containing a sequence of commands that can be initiated with a single
command button or event.
Macros are useful for customizing your forms in any number of ways. For instance, you can save
time and effort for your users by defining a series of steps that execute automatically with a
single click. You can use a macro to automatically validate user input before it is entered in the
table. You can automate complex surveys with many branches using conditional (if-then-else)
logic. You can even make your forms dynamic by having macros execute automatically when a
given event occurs, such as when the form opens or the user changes a field value.

Components of a Macro:
A macro consists of a sequence of commands that you want performed in a given order.
“Cellica Database” offers a large library of commands that you can use as steps in a macro.
Most commands have parameters you must specify, such as values read into or written out by
the command. For these values, you can supply a constant or an expression. Expressions can
read values stored in a table column for the current record as well as apply mathematical
operations, if-then-else logic, and functions to return a desired value.
The script commands can execute in a straight linear sequence, or you can incorporate skips,
branches and loops based on conditional logic using Skip commands. You can also have
“SubMacros” within a “Macro”. SubMacros are a sequence of commands that you write once,
and can then call from the main script as many times as needed. Simply write the SubMacros as
you would any other, then call it from the main script using a "Run macro" command.
One “Cellica Database” form can have any number of macros. However, each macro is "built
into" a single “Cellica Database” form; it is not possible to call an external macro.

Create a Macro:
Create a new form or open an existing form using “Edit Form” option on “File Manager”.
Click on “Macros” present in the Form’s“Form and Tab Properties” control.

_____________________________________________________________________________________
Cellica Database – Macros and Events

Fig 1: “Macros” Property in “Form and Tab Properties” Control

You will be presented with following “Macro Builder Dialog”

Fig 2: “Macro Builder”
_____________________________________________________________________________________
Cellica Database – Macros and Events

b) Remove Macro: Use this option to remove selected macro in “Macro Name” list from current form. _____________________________________________________________________________________ Cellica Database – Macros and Events .Using various options on “Macro Builder” a) Add New Macro: Use this option to add new macro to the current form. Fig 3: Enter Name for Macro Please Note: You can’t use same macro name twice in the current form. click “Add New Macro” Button and provide Macro Name. a) Add New Macro: To create new macro.

Now we will design our newly added macro. Fig. 4: Add New Macro _____________________________________________________________________________________ Cellica Database – Macros and Events .

By default it is added to last. 4) Remove selected: It will remove the selected command from macro steps. 2) Insert Before: It used to insert the command before to the selected command in macro steps. 4: Add command in New Macro 1) Add Command: Click on “Add Command“ button to add command to the macro and select the command you want to use in macro from “Command Name” drop down list. 3) Insert After: It used to insert the command after the selected command in macro steps. _____________________________________________________________________________________ Cellica Database – Macros and Events .Fig.

(Set Caption. Commands: Command is a action executed on current form. Control Name: Control ID c. Set Mandatory. Set Font Size. Set Forecolor. Font Size. _____________________________________________________________________________________ Cellica Database – Macros and Events . Following commands are supported in “Cellica Database” Macro builder. 1) Set Property: Arguments list: a. Values: Depending on “List Type”. a) Commands with arguments b) Commands without arguments For Example: “Set property” command has three arguments: 1) Property: List of properties used with control. Back Color. For Example: With “Set Property” command you can set the property of control. Read Only. Set Font Name. Caption. Set Backcolor. Fore Color etc) 2) Control: List of controls as per property selected in “Property”. Property: Property to set. Mandatory. Show/Hide Control. Fore Color.) b.(Caption.5) Remove All: It will remove all the command from selected macro. Use to set a property for a control on a form. Use this with conjunction with combo box control on form. Value: Value for selected property. Read Only. 3) Value: Required Value to assign to “Property” of selected “Control”. List of items or set list from another combo box. Font Name. Show/Hide Control. You can set new list of items or set list from another combo box to specified combobox control. Show/hide Control. Control Name: Control ID b. List Type :Constant List or Combo Box list c. There are two types of commands depending on arguments they needed. 2) Set New List: Arguments list: a.

if this statement is included in a submacro. 8) Return From Macro: Stop the execution of the current macro and return to control process which called it. c. processing does not return to the main macro. 7) Stop Macro You can use the "Stop Macro" action to stop the current macro. 9) Record|First: Go to first record in the table. 5) Macro Step Label: Argument List : a. if included in main macro. based on the current sort order. It is used for identify destination for "GoTo" clause in "Skip" command expression. processing returns to the form. _____________________________________________________________________________________ Cellica Database – Macros and Events . This "Step Label" need to be use in "GoTo" label in skip command. Assign the “Control/Column/constant/expression” value to specified control or column.3) Set Focus: Sets focus to specified control on form Arguments list : a. processing returns to the main macro. Either Control ID or Column Name. 6) Run Macro: Runs a specified Macro Argument List: a. Source Value Type: Control or Column or Expression or Constant d. Destination Value Type: Either Control or Column. Typically use it when an error condition is detected. Control Name: Control ID 4) Assign: Argument List : a. b. If included in a submacro. Step Label Use "Step Label" to jump to specific command using Macro Step Label. Destination Value: Select Value depending on Destination Value Type. Macro Name: Name of macro to run. Recommended as the last step in every macro. Source Value: Enter value according to Source Value Type.

based on the current sort order. based on the current sort order. it can be used to create conditional branches and loops.For GoTo Label: provide Label Name. 16) Record|Search: Finds the first record (based on the current sort order) whose value in a specified table column matches a search value.10) Record|Previous: Go to previous record in the table. . GoTo Label and If-Then-Else . 11) Record|Next: Go to next record in the table. 21) Message Box: Argument List : a. 18) Record|Close: Close current record. based on the current sort order.For If-Then-Else: If part. 13) Record|Insert: Insert a new record. 19) Select Tab: Selects a specific tab. . 14) Record|Delete: Removes current record. Message Text : Message to display in message box.For Number: provide the Number of statements to be skip. 12) Record|Last: Go to last record in the table. Number: Tab Number 20) Skip: Argument List: a. then part and else part. b. Skip Message: (True or False): _____________________________________________________________________________________ Cellica Database – Macros and Events . 17) Record|Save: Save the current record. Skip forward in the macro sequence. 15) Record|Duplicate: Create a new record by creating a duplicate copy of the current record. Argument: a. Skip Type : Number.

Message box will show “Yes” and “No” buttons. 22) Open Form: Argument List : a. Close Form: (True or False): If “True” then the parent form will be closed before opening new form. A Common use is a message that appears when validation fails. opened form will be stacked over the Parent form. Expression can be used with three commands: 1) Assign 2) Select Tab 3) Skip For Example: 1) $ColumnName*2/10 Column name is prefixed with $ in expression. - If set to “False”.If set to “True”. When “OK” button is pressed the execution of macro will continue from next command. If user press “Yes” button then command next to “Message Box” command will be skipped. 2) [TextBox]*2/10 Form control is used In [Control] open and close brackets. Form Name: Form to open. 3) 10 * 100/100 Numeric values can be used in expression. Expression: You can assign result by executing expression in command. If “False”. Displays a message box containing a warning or information message. If “No” button is pressed the execution of macro will continue from next command. b. Open a specific form. _____________________________________________________________________________________ Cellica Database – Macros and Events .. Message box will show only “OK” button.

Date Time functions for expression Formats of fixed date value used in date time functions: Fixed Format : (Time 24 hour) Date : "dd-MM-yyyy" Time : "HH:mm:ss" DateTime : "dd-MM-yyyy HH:mm:ss" User can use "date/datetime/Time" values in these functions by using Constant date in given format/Column containing datetime value/ControlID of control mapped wit date time type column 1) Now(Flag) Parameter: Flag : 0 .DateTime Return current date/time/datetime. 2 . 1 .Day. Cnt) Parameter: Flag: 0 . 3) Substract (date. date2) Return the date difference in number of days.Day.Month. Flag.Month.Time. Cnt) Parameter: Flag: 0 . 2 – Year Cnt : Number of Day/Month/Year Return date calculated by adding no of Day/Month/Year in given date. 1 . 1 .Date. 2) DateDiff(date1. Flag. (date2-date1) Add(date. 2 – Year _____________________________________________________________________________________ Cellica Database – Macros and Events .

Second Returns Time type value by adding Hour/Minute/Second in given Time. For example. _____________________________________________________________________________________ Cellica Database – Macros and Events . 6) MonthName(date) Returns the name of the month in given date. DayNameOfWeek(14/02/2002) returns Thursday. Cnt) Parameter : Flag : Hour. 7) DayNameOfWeek(date) Returns the name of the day for datetime.Cnt : Number of Day/Month/Year Return date calculated by subtracting no of Day/Month/Year from given date. MonthName (14/02/2012) returns February. 8) DayOfMonth(date) Returns the day of the month for given date (integer in the range 1-31). 11) TimeDiff(Time1. 4) Year (date) Return the year component of given date. 9) DayOfWeek(date) Returns the day of the week for given date as an integer in the range 1-7(where 1 represents Sunday). For example. For example. Flag. Time2) Returns difference in number of milliseconds (Time2-Time1) 12) Time Add(Time. 5) Month(date) Return the Month component of given date ( integer in the range 1-12). Minute. DayOfYear(02/02/2012)returns 33. 10) DayOfYear(date) Returns the day of the year for given date as an integer in the range 1-366.

Flag. String DateTime Format "DD/MM/YYYY HH:MM:SS" _____________________________________________________________________________________ Cellica Database – Macros and Events . String Date Format "DD/MM/YYYY" 19) Time StringToTime(String) Returns Time from String. 16) Second(datetime) Returns the second in datetime as an integer in the range 0-59. String Time Format "HH:MM:SS" 20) DateTime StringToDateTime(String) Returns DateTime from String. Second Returns Time type value by subtracting Hour/Minute/Second from given Time 14) Hour(datetime) Returns the hour in datetime as an integer in the range 0-23.13) Time Substract(Time. Cnt) Parameter : Flag : Hour. Minute. 17) String ConvertToTimeString(Flag) Parameter : Flag:milisecond/Second/minute Returns Time String As "HH:MM:SS" 18) Date StringToDate(string) Returns Date from String. 15) Minute(datetime) Returns the minute in datetime as an integer in the range 0-59.

text2) Returns: String value by appending Text2 at the end of Text1.String functions 1) Concat ( text1. .substring("XYZ". $ColumnName) .substring(ConvertToString([ControlID]). through the number of characters specified by length.Concat([ControlID]. For example. left($ColumnName)) . Parameters: First parameter :ControlID/ Column Name/ Constant String value/ String functions.substring([ControlID]. start.Concat(ConvertToString([ControlID]). length($ColumnName)) . "Abc") _____________________________________________________________________________________ Cellica Database – Macros and Events .Second and Third parameter: Number constant or length() function.indicates the first character position). . Parameters: ControlID/ Column Name/ Constant String value/ String functions. 0. "Abc") 2) Substring( text. For example. beginning at the character position specified by start (1. 0.Concat("XYZ". $ColumnName) . length) Returns: Characters in text. 0.

start. "XYZ". For example. where number of characters specified by length have been deleted from text. For example. "Abc") . "Abc") 4) Replace(text. Parameters: ControlID/ Column Name/ Constant String value/ String functions. insert_text) Returns: a string. length($ColumnName). . length("XYZ"). and where insert_text has been inserted into text. Searches text for “search_string”. beginning with the character position indicated by the value of start. replacement_text) Returns: a string. 0.replace([ControlID].replace("XYZ". Parameters: First and Fourth parameter: ControlID/ Column Name/ Constant String value/ String functions. beginning at start.3) Insert(text. "Abc") _____________________________________________________________________________________ Cellica Database – Macros and Events . "Abc") .insert("XYZ". "YZ". 0.insert(ConvertToString([ControlID]). . $ColumnName) . and replace with “replacement_text” in all occurrences. 0.insert([ControlID]. length. $ColumnName) .replace(ConvertToString([ControlID]). "XYZ". length($ColumnName). search_string.Second and Third parameter: Number constant or length() function.

For example.Left(ConvertToString([ControlID]).length(ConvertToString([ControlID])) . count ) Returns: a string. Parameters: First parameter: ControlID/ Column Name/ Constant String value/ String functions.Second parameter: Number constant or length() function. Parameters: ControlID/ Column Name/ Constant String value/ String functions.Left("XYZ".length([ControlID]) . with the rightmost “count” number of characters in text. excluding trailing blanks. 10) .Left([ControlID]. For example. Parameters: First parameter: ControlID/ Column Name/ Constant String value/ String functions.length("XYZ") 6) Left(text.5) Length(text) Returns: the number of characters in text.Second parameter: Number constant or length() function. 5) . with the leftmost “count” number of characters in text. 3) .length($ColumnName) .Left($ColumnName. . . _____________________________________________________________________________________ Cellica Database – Macros and Events . 2) 7) Right(text. count ) Returns: a string.

10) . start) Returns: Returns the starting position of the first occurrence of “search_string” within “text”.right("XYZ".locate("abc". .ltrim(ConvertToString([ControlID])) . "XYZabc". [ControlID].ltrim($ColumnName) . 10) . in case of “search_string” do not found. without leading blanks.locate("abc". ConvertToString([ControlID]).ltrim(" XYZ") _____________________________________________________________________________________ Cellica Database – Macros and Events . text. Parameters: First and Second parameter: ControlID/ Column Name/ Constant String value/ String functions.locate("abc".right($ColumnName. Returns 0. The search begins with the character position indicated by the value of start (1 indicates the first character position). 3) . For example. 2) 9) Ltrim(text) Returns: a string. with characters in the “text”. 5) . 3) . 5) . .right([ControlID].locate("abc".right(ConvertToString([ControlID]). For example. Parameters : ControlID/ Column Name/ Constant String value/ String functions. 2) 8) Locate(search_string.For example.Third parameter: Number constant or length() function. . $ColumnName.ltrim([ControlID]) .

repeat([ControlID].rtrim($ColumnName) .10) Rtrim(text) Returns: a string.rtrim([ControlID]) . For example. without trailing blanks.rtrim(ConvertToString([ControlID])) . "ab") 12) Lcase(text) Returns: a string. "ab") . with characters in the “text”. . "aa") . the repeated count times “search_text” is found in text. For example.repeat(ConvertToString([ControlID]). search_string) Returns: a number. Parameters : ControlID/ Column Name/ Constant String value/ String functions. .repeat($ColumnName. For example. with text as all characters in lowercase Parameters : ControlID/ Column Name/ Constant String value/ String functions.lcase(ConvertToString([ControlID])) _____________________________________________________________________________________ Cellica Database – Macros and Events . "aa") .repeat("XYZAbc".rtrim(" XYZ") 11) Repeat(text . . Parameters: First and Second parameter: ControlID/ Column Name/ Constant String value/ String functions.

if you select this option then it will be ask for three argument. 1) Skip type : There are three skip types i) Number: Skip the specified number of step from current step. A) if part: In this part you need to provide the condition. with text as all characters in uppercase Parameters: ControlID/ Column Name/ Constant String value/ String functions.ucase(ConvertToString([ControlID])) .ucase($ColumnName) .lcase("XYZ ") 13) Ucase(text) Returns: a string. For example.ucase("XYZ ") Conditional branches and Loops: You can use condition branches and loops with skip command.lcase($ColumnName) .. For Example: $Age > 10 OR [TextBox] > 10 Here $Age is the Column Name and [TextBox] is the control name.lcase([ControlID]) .ucase([ControlID]) . ii) Goto Label: Jumps directly to specified macro step label. iii) If-then-else: Using this you can implement conditional branching and looping. If you want to check multiple condition then you can use (OR. . Skip command have 2 argument. B) then part : _____________________________________________________________________________________ Cellica Database – Macros and Events . AND and NOT) operator.

First is the label value assigned to the macro step label command. For Example: 1) 2 2) $Age+10 3) goto First. _____________________________________________________________________________________ Cellica Database – Macros and Events . C) else part : If “if condition” is evaluated to false then this part will be processed Here you can use constant value or expression or goto clause.First is the label value assigned to the macro step label command.If “if part” is evaluated to true then this part will be processed Here you can use constant value or expression or goto clause. For Example: 1) 0 2) $Age+10 3) goto First .

_____________________________________________________________________________________ Cellica Database – Macros and Events . 5:Conditional branches and Loops.Fig.

a) Form Level Event Fig. You need to select the macro for particular event. 3) OnStartup: When form is load. _____________________________________________________________________________________ Cellica Database – Macros and Events . this event is called up for old record.6: Form Event Property Supports following events.Events: You can initiate/execute a macro on particular event. 4) OnRotate: When orientation changed. There are three types of event groups: a) Form level events b) Control level events c) Radio group events To execute macro on particular event you need to use “Event” property on one of the above mentioned event groups. 1) OnRecordDisplay: When navigated to another record( First/Last/Previous/Next) 2) OnLeavingRecord: When record is moved in navigation.

2) Lost Focus: When focus is moved from control.Fig. _____________________________________________________________________________________ Cellica Database – Macros and Events . 7:Set macros for Form Level Event. b) Control Level Events Fig 8: Control Event Property i) TextBox/Location/Formula Field control event Supports following events. 1) Get Focus: When focus is set in control.

_____________________________________________________________________________________ Cellica Database – Macros and Events . 1) Get Focus: When focus is set in control. 9:Set macros for Control Level Event. 3) Changed: Value of control is changed Fig.Fig. ii) Combobox/CheckBox/RadioButton(Group) control event Supports following events. 10:Set macros for Radio or Combo box or Checkbox Event iii) Button control event: Supports following events. 2) Lost Focus:When focus is moved from control. Clicked: Clicked on button.

3) Changed: Selection in Radio Group is changed. Fig. 12: Radio Group Event Property Supports following events. c) Radio Group Event: Fig. 2) Lost Focus: When focus is moved from control. 11:Set macros for button Event.Fig. 13: Set macros for Radio Event _____________________________________________________________________________________ Cellica Database – Macros and Events . 1) Get Focus: When focus is set in control.