Mioplanet Documentation Center
Resources and Help
HomeProductsMioScriptJavaScriptTechNotesPHP
   Home | MioScript | MioScript: Functions SEARCH    


  TechNotes
About MioEngine
About MioScript
Adding a Login feature
Admin Panel Configuration File: Account
Admin Panel Configuration File: Alerts
Admin Panel Configuration File: Channels
Admin Panel Configuration File: Servers
Admin Panel Configuration File: Software
Admin Panel Configuration File: Tasks
Admin Panel Installation Troubleshooting
Deploying an application remotely
Get the real size of a web page
How to create a Business Card
How to create a Desktop Alert
How to create a Desktop Ticker
How to create a Scrolling Alert Software
How to create a Scrolling Ticker
How to create a simple RSS Reader
How to debug
Installing Admin Panel on a server
LCD Monitor Chart: Screen Resolution, Size, Pitch, Display Area
Managing read marks
Measuring Elements in JavaScript
Media center remote control
Mio File Format
MioScript: Conditions
MioScript: Events
MioScript: Functions
MioScript: Loops
MioScript: Variables and Data Types
Programming MioScript
Statistics: How to track users and actions
Where to host Mioplanet Admin Panel
XML Configuration File Format

  MioScript Reference
> Statements
app...
browser...
dialog...
disk...
draw...
extern...
filename...
keyboard...
menu...
mio...
mouse...
num...
path...
pushButton...
reg...
RS232...
sci...
screen...
shortcut...
sound...
str...
system...
time...
var...
window...

  Products
All Products
MioDB
MioFactory
Mioplanet Admin Panel

TechNote
MioScript: Functions

Language: MioScript


 Functions are blocks of code you can call from another code.
Functions are used to avoid repetitive code and to make the source code easier to read.

To declare a function:

function.myFunction
    ...
function.end


The function can be called from an event or another function as follow:

myFunction()


To return a value:

function.myFunction
    ...
    return(&valueToReturn)
function.end


And to retrieve the returned value of a function:

&myVariable = myFunction()



For more information: function.functionName, function.end, return

 

Passing Parameters
 
Parameters are values you can send to a function.
The parameters can be sent by value (easier way) or by reference (if the function needs to update the content of a variable).

By Value

Parameters can be passed to the function as follow:

event.load
    ...
    myFunction(&myParam1, &myParam2)
event.end

function.myFunction(&getParam1, &getParam2)
    ...
function.end



By Reference

Variables can also be passed by reference. The name of the variable is sent instead of it's value, so the function can update the content of the variable.

To send a variable by reference, proceed as follow:

event.load
    ...
    &myVariable = "Hello"
    myFunction(myVariable)
event.end

function.myFunction(&variableName)
    alert(&_variableName)
function.end


The underscore is used to retrieve the value of the variable.
You can also set the value of the variable as follow:

&_variableName= "Good-bye"


The value of myVariable is set to Good-Bye.

As &variableName = myVariable, the two following lines are equivalents:

&_variableName= "Good-bye"
&myVariable= "Good-bye"


 
Keywords in functions names
 
It is possible to add keywords in a function name.
Here is a declaration of a function with a keyword:

function.myFunction:keyword
    ...
    return(&valueToReturn)
function.end


To call this function:

myFunction.keyword()


You can add as many keyword as you want. This can help to group functions by family.

 

Passing a function as a parameter
 
Passing a function to a function as a parameter can save many lines of code.

In the following example, a function is passed as an argument to a function.

event.load
    callAndShowResult(getHello)
    app.close()
event.end

function.callAndShowResult(&function_name)
    _&function_name()
function.end

function.getHello()
    alert("Hello")
function.end


The function is called with an underscore behind the variable name.

Important: It is not possible to retrieve a return value when calling a function with a variable.