Basic VBScript for Elipse E3: Lesson 10 – Procedures and Functions

Procedures are code lines, used to respond to events and execute actions. Procedures do not return values and are identified by the Word Sub in their declaration. All procedures must start with a letter, and can contain letters, numbers and underscore character.

Functions are used to execute calculations and test values, and always return something. An example would be to sum two values and return the value of the sum.

Example:

Sub CommandButton1_Click()
    ‘Function Sum
    answer = Sum(10,20)
    MsgBox answer
   
    ‘Sub display message
    DisplayMessage(“Message to be displayed”)       
End Sub

Function Sum(a,b)
    Sum = a + b
End Function
   
Sub DisplayMessage(message)   
    MsgBox message
End Sub

Exercises:

1. Create a button that contains a Function that adds, multiplies and divides two numbers and displays each answer on a message box.
2. Create the following alarm structure:


Figure 17

3. Link each digital alarm to an internal tag. To change the value of the internal tag, use ToogleButton on screen.
4. Create a button that displays a message box for all alarm objects. The message must inform whether it is an area or a digital alarm, and the name of the object. Tip: for each object, check the Typename. Create a Sub for area type objects and another Sub for source type objects.

Attachments:

Lesson10.zip

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *