Example Procedures

You may write a procedure for:
To write procedures, you need to have a basic level of understanding how to write algorithms. If you are somewhat familiar with mathematical expressions, it's not a big deal to start your own procedures by trying and working on the example codes given on this page.
When writing procedures,

Tip:
There is an application template which shows and guides thru a number of script examples in version 5.5 and later. You may get a good idea about how to implement computed field expressions or action driven scripts by examining that template. To import this template, click "Design" menu, select "Import Application Template" and then select the template "Calculation and Scripts". This will create one new catalog named as "Script Examples". Create a new record on this catalog and check each of the examples explained on that record window.


Example #1: Computed Field With a Procedure

For the example given below,
- Create a text field named "Name Surname",
- Create an option list field named "Gender", with the options "Male" and "Female"
- Create a computed field setting compute type as "procedure" and return type "calculate to text".
- Copy and paste the code given below into the procedure box.



After creating all fields, type any name into the name box and change gender to see what happens.


Example #2: Displaying Conditional Objects

For the example given below,
- Create a text field titled "First Name",
- Create a text field titled "Last Name",
Open Form Designer, select Toolbox tab,
- Create a label with the text content "Please fill in the name box!".
- Open properties of the label and set the object name as "MyLabel".
- Create a script object, copy and paste the code given below into the procedure editor.
- Click to "Triggering Events" tab, add the following events: "Field Modified", "Load New Record", "Load Existing Record"




Example #3: Changing Background Color

For the example given below,
- Create a text field titled "Name",
Open Form Designer, select Toolbox tab,
- Create a script object, copy and paste the code given below into the procedure editor.
- Click to "Triggering Events" tab, add the following events: "Field Modified", "Load New Record", "Load Existing Record"
This example requires version 5.6.0 or later.




Example #4: Displaying a Data Field On All Tabs

For the example given below,
- Create a text field titled "Name",
Open Form Designer, select Toolbox tab,
- Create a script object, copy and paste the code given below into the procedure editor.
- Click to "Triggering Events" tab, add the following event: "After Change Tab"




Example #5: Disable Saving Record If Required Field Was Left Blank

For the example given below,
- Create a text field titled "Name",
Open Form Designer, select Toolbox tab,
- Create a script object, copy and paste the code given below into the procedure editor.
- Click to "Triggering Events" tab, add the following events: "Before Create Record", "Before Update Record"




Example #6: Creating Keyboard Shortcuts

For the example given below, open Form Designer, select Toolbox tab,
- Create a script object, copy and paste the code given below into the procedure editor.
- Click to "Triggering Events" tab, add the following events: "Key Press"




Example #7: Download Currency Exchange Rates From a Web Site

For the example given below,
- Create a text field titled "Current Rate",
Open Form Designer, select Toolbox tab,
- Create an action button, copy and paste the code given below into the procedure editor.




Example #8: Push Notification to Mobile Devices by Clicking a Button

This example illustrates sending a push notification message to a mobile phone by clicking a button. There are various online push notification services available on the internet. We used here the service provided by pushover.net. You must install their mobile application and register your notification application on their web site before you can use this example.

For the example given below, open Form Designer, create an action button, copy and paste the code given below into the procedure editor.




Example #9: Send Email From Your Web Site

This example requires your web site to have a compatible server side script which receives the data you send and then sends an email using the information included in the data.
For the example given below,
- Create a text field titled "To Address",
- Create a long text field titled "Message Body",
Open Form Designer, select Toolbox tab,
- Create an action button, copy and paste the code given below into the procedure editor.




Example #10: Executing SQL Queries in a Loop

For the example given below,
- Create a new catalog titled "Test Catalog",
- Create a new field on that catalog titled "Name",
- Create a few records on that catalog filling the name field with example names using lower case letters.
Open Form Designer, select Toolbox tab,
- Create an action button, copy and paste the code given below into the procedure editor.




Example #11: Exporting Records in a View to CSV File

The following code exports data from a number of specified fields from all records of a specified view.
Open Form Designer, select Toolbox tab,
- Create an action button, copy and paste the code given below into the procedure editor.

You must replace the catalog name, view name and field names below according to the actual object names in your database.
You may add more lines to export more fields. Replace also the export file path.

Tips:
- If you save this script as a scheduled script task, you may let it execute automatically with periodic time intervals.
- Remember to replace the function SQLGetField used below with SQLGetFieldValue if you want to retrieve data from option list or relational lookup field (requires version 5.6.0).











Online Help Home Page   ::   SpeedBase Software Home Page