Pick up where you left off on this computer

Resume

 

 

 

Skip Navigation Links.

Introducing Functions

Now that you have written an expression using the ShowForm function, let's take a closer look at how Functions work.
 
A function is a piece of pre-defined code that instructs your application to perform one or more tasks. Rather than writing out the function's code in full each time you want to use it, you initialise the function using a short snippet of code known as a Function Call.
 
Each call consists of the function's unique keyword followed immediately by a set of round brackets (parentheses). This is collectively known as the function's Syntax. For example, the following expression consists of a single function call:
 
GetDate();
Here, GetDate is the function's Keyword. In this case, the parentheses are empty because the GetDate function does not require any further information to be able to run. Some functions, however, require you to write additional information in the parentheses, in the form of a series of comma-separated values known as Arguments.
 
The function you learned in the previous topic - ShowForm - requires a single argument before it will work. This argument is the name of the form you want your application to load. Here's an example:
 
ShowForm("MyGroupName");
 
It helps to think of an argument as the answer to an enquiry. In the above example, the enquiry is "what is the name of the group you want to display?". In a function call, this enquiry is called a Parameter. Each function has its own unique set of parameters, and as such will require you to provide a matching set of arguments for it to work correctly.
 
Depending on the parameter, the argument might need to be a number, a text string, True, or False. In the case of ShowForm, the parameter is a simple text string containing the keyword of a question group.
 

It is very important that the order of arguments in your function call matches the order of the function's parameters. If you mix up your arguments, your expression will behave unexpectedly - or simply not work at all! Consider the following function call, which includes two arguments:

Chr( String, Index );
 
The Expression Engine reads the arguments from left to right, so if you were to write the Index argument first, it will think you're providing a value to the String parameter, and vice versa.
 
You'll be using functions quite regularly for the rest of this course, so be sure to check this topic again if you need any help understanding the basics.

Found a problem or something unclear? Get help or provide feedback on this page by completing this form.

= four + seven