PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
This content comes from an automatic translation.
  • NOTE1
  • 1410087510
  • In this lesson
  • NOTE4
  • NOTE4_1
  • //############
  • The procedure code has the following format:
  • //############
  • Calling a procedure/a function
  • PROCEDURE Multiplication(Nb1 is int, Nb2 is int)
  • PROCEDURE Test_value(LOCAL P1)
  • //############
  • In this example
  • See the online help for more details (keyword
  • Create two numeric edit controls containing the value BT and the value IOT.
  • //############
  • //############
Appendix 5. The procedures
] ]
NOTE1
  • NOTE1_1
  • This lesson will teach you the following concepts
  • Types of procedures.
  • Creating and calling a procedure.
  • Procedure parameters.

Procedure result.: Practical example.
Previous LessonTable of contentsNext Lesson
1410087510
NOTE2
NOTE2_1.
In this lesson
NOTE3
  • NOTE3_1: Types of procedures
  • Three types of procedures are available:: Global procedure
  • can be used in all project the events and processes of the project (declared in a set of procedures).: Local procedure in a Window, Page or Mobile Window
can be used in all the events and processes that depend on the object in which this procedure was declared.

Internal procedure in a process or event

can only be used in the process or event where it was declared.
Remark.
NOTE4

NOTE4_1

Creating and calling a procedure
  1. Global procedure. To create a global procedure, you must:.
  2. Create (if necessary) a set of procedures (via the "Project explorer" pane, "Procedures" folder). Give a name to the set of procedures
  3. Create a global procedure in the set of procedures (via the "Project explorer" pane, "Procedures, Set name" folder). Give a name to the procedure.
    Type the code of global procedure

//############

PROCEDURE ()
  1. NOTE4_2.
  2. Local procedure
  3. To create a local procedure, you must:.
  4. Select the element associated with the procedure (window, page, etc.). Create a local procedure (via the "Project explorer" pane, expand the element name, "Local procedures" folder).
    Give a name to the procedure

The procedure code has the following format:

//############
PROCEDURE <Name of local procedure>()
NOTE4_3
Internal procedure

//############

INTERNAL PROCEDURE ().
<Code of internal procedure>
END
%00000070% %00000070%]] for more details.|

Calling a procedure/a function

See the online help for more details (keyword
"Procedure").
NOTE5
NOTE5_1. Procedure parameters
What is a parameter?. A parameter is a value sent to a procedure during the call to the procedure.
Multiply10(50)
You can pass 0 or several values as parameters to a procedure

These values can be of any type (as with variables).

The parameter is specified in the procedure declaration in the format of a variable
For example, for the Multiply10 procedure, the procedure code is:
PROCEDURE Multiply10(P)
P=P*10
PROCEDURE Multiplication(Nb1 is int, Nb2 is int)
MyResult is int
MyResult = Nb1 * Nb2
RESULT MyResult
//############
res is int
res = Multiplication(10, 50)
// Res is equal to 500

PROCEDURE Multiplication(Nb1 is int, Nb2 is int)

MyResult is int. MyResult = Nb1 * Nb2
RESULT MyResult
The code used to call the procedure is as follows:
  • //############
    PROCEDURE Test_address(P1)
    P1 = P1 * 2
  • // Res is equal to 500
    T is int
    T = 12 // T is equal to 12 before the call
    Test_address(T)
    // T is equal to 24 after the call
Therefore, when a procedure statement modifies the parameter value, the value of the variable corresponding to this parameter is modified.. Example:. The procedure code is as follows:
//############. PROCEDURE Test_address(P1)
P1 = P1 * 2
  • The code used to call the procedure is as follows:
    PROCEDURE Test_value(LOCAL P1)
    // Local indicates that the parameter will be passed by value
    P1 = P1 * 2
  • Test_address(T)
    T is int
    T = 12 // T is equal to 12
    Test_value(T)
    // T does not change
To force a parameter to be passed by value to a procedure

This keyword indicates that the following parameter will not be modified by the procedure.

Example:. The procedure code is as follows:.

PROCEDURE Test_value(LOCAL P1)

// Local indicates that the parameter will be passed by value. P1 = P1 * 2: The code used to call the procedure is as follows:
//############

T is int

T = 12 // T is equal to 12.
Test_value(T). // T does not change. Remark.
PROCEDURE Multiplication(Nb1 is int, Nb2 is int=10)
MyResult is int
MyResult = Nb1 * Nb2
RESULT MyResult
The parameters received in the procedure can be mandatory or optional parameters
res is int
res = Multiplication(6)
// Res is equal to 60
When declaring a procedure, the optional parameters are the last parameters (they are always specified after all mandatory parameters). In the following example, the Multiplication procedure uses an optional parameter, Nb2.
//############
PROCEDURE Multiplication(Nb1 is int, Nb2 is int=10). MyResult is int. MyResult = Nb1 * Nb2
RESULT MyResult
In this example
NOTE6
  • NOTE6_1
  • Result of a procedure
  • The procedures can return one or more results
The result can be typecasted
The RESULT keyword must be used to return a value.: See %00000163% %00000163% for more details.

See the online help for more details (keyword

Result).. NOTE7
  • NOTE7_1.
    1. Practical example.
    2. Using a procedure

Create two numeric edit controls containing the value BT and the value IOT.

  • Create a Combo Box control used to choose the VAT rate.
    1. Create a Button control used to calculate and display the value IOT of the amount BT entered.. The calculation result will be displayed in the "Price IOT" control.: This page is as follows.
    2. Test page of a procedure
    3. NOTE7_2. Project used. To handle the different concepts of this lesson, we are going to create different pages
    4. These pages will be created in the "My_First_Pages" project.. Open the "My_First_Pages" project if necessary
    5. Open the WEBDEV home page (Ctrl + <)
  • Click "Tutorial", then "My first pages (Exercise)".
    1. NOTE7_3. Implementation. Create a new blank page:
    2. Click among the quick access buttons
    3. The element creation window appears
      • click "Page" then "Page"
      • The page creation wizard appears.
    4. Create an element
  • Select "Blank".
    1. Validate. The page is automatically created in the editor. The window for saving an element is displayed.
    2. Specify the page title: "Procedures": The page name ("PAGE_Procedures") is automatically proposed.
      • Validate the save window ("OK").
      • To create the edit control corresponding to the price BT:
    3. On the "Creation" pane, in the "Usual controls" group, expand "Edit" (click the arrow). The list of available edit controls is displayed
    4. Select the "Currency" control and position the control in the page.
    5. Right-click the control and select "Description".
  • In the description window:
    1. Type the control name: "EDT_PriceBT".
    2. Type the caption: "Price BT".. Validate.
    3. To create the control where the result will be displayed:. On the "Creation" pane, in the "Usual controls" group, expand "Edit" (click the arrow)
    4. The list of available edit controls is displayed
    5. Select the "Currency" control and position the control in the page (below the edit control displaying the price BT for example).. Type the control information
    6. right-click the control and select "Description".
      • Specify the control name: "EDT_PriceIOT".
      • Modify the caption to "Price IOT".
      • The result displayed in this control must not be modifiable
      • Click the "UI" tab and choose "Read-only" for the initial status.
      • Validate.. Save the page (Ctrl + S).
    7. To create the Combo Box control for VAT selection:. On the "Creation" pane, in the "Usual controls" group, click "Combo box" then click the position where the control will be created in the page (beside the "Price BT" control).
    8. The Combo Box control creation wizard is displayed
    9. This wizard allows you to easily define the main characteristics of the control..
  • Select the option "Fill the Combo Box control by programming or enter a list of values":
    1. .
    2. Combo Box control creation assistant.
  • Go to the next step of the wizard.
    1. Keep the default options
    2. Go to the next step of the wizard.
    3. In the "Initial content" step, type the list of possible VAT values:. 5.5. Press the Enter key.
    4. 10
  • Press the Enter key.
    1. 20

    2. SWITCH COMBO_VAT..DisplayedValue
      // 5.5 %
      CASE 5.5
      EDT_PriceIOT = EDT_PriceBT * 1.055
      // 10 %
      CASE 10
      EDT_PriceIOT = EDT_PriceBT * 1.1
      // 20 %
      CASE 20
      EDT_PriceIOT = EDT_PriceBT * 1.2
      END

      Creating a Button control
    3. Click the control that was just created. The text displayed in the button becomes editable. Type the caption: "Calculate".
Press Enter to validate the input.. The amount IOT will be calculated via the code of the "Calculate" Button control.
  • Display the code of "Calculate" control ("Code" from the popup menu).

//############

  • SWITCH COMBO_VAT..DisplayedValue
    1. // 5.5 %
    2. CASE 5.5
    3. EDT_PriceIOT = EDT_PriceBT * 1.055
    4. // 10 %.
    5. CASE 10
    6. EDT_PriceIOT = EDT_PriceBT * 1.1
      PROCEDURE Calc_IOT(PriceBT, VATRate)
      cyIOT is currency
      cyIOT = PriceBT * (1 + VATRate/100)
      RESULT cyIOT

      This code calculates the amount IOT by using the value selected in the Combo Box control (returned by %00000264% %00000264%).
      • ..DisplayedValue: Run the page test ( among the quick access buttons)
      • Give a price BT. Select the different values in the Combo Box control and click "Calculate".
      • Run the test of a page
    7. Calculation test.
      Our page operates properly now

      However

      Close the test page to go back to the code editor.. NOTE7_4
      Creating and using a procedure. To create the procedure for calculating the amount IOT:.
  • Click the page background.
    1. Display the events associated with the page (F2).
    2. In the code editor, on the "Code" pane, in the "Procedures" group, expand "New" and select "New local procedure (Server)".
    3. In the window that is displayed, type the name of local procedure ("Calc_IOT") and validate ("Add" button)
      SWITCH COMBO_VAT..DisplayedValue
      // 5.5 %
      CASE 5.5
      EDT_PriceIOT = Calc_IOT(EDT_PriceBT, 5.5)
      // 10 %
      CASE 10
      EDT_PriceIOT = Calc_IOT(EDT_PriceBT, 10)
      // 20 %
      CASE 20
      EDT_PriceIOT = Calc_IOT(EDT_PriceBT, 20)
      END
This variable is used to store the calculated price IOT.. This procedure calculates the price IOT and returns the calculated value.: Close the code editor. Remark.

  • When creating a procedure, comments are automatically generated BEFORE the procedure code
    1. These comments are mainly used to specify the content of parameters and return value.. It is important to fill these comments. Indeed, they will be automatically displayed in a tooltip when typing the call to the procedure in the code editor
    2. All you have to do is call the procedure from the Button control.
    3. Select the "Calculate" Button control.
//############
SWITCH COMBO_VAT..DisplayedValue. // 5.5 %. CASE 5.5
EDT_PriceIOT = Calc_IOT(EDT_PriceBT, 5.5)
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 24
Comments
Click [Add] to post a comment