Tuto WINDEV 25

80 Part 2: The WLanguage basics 3. Close the code window (click X at the top right corner of code editor). 4. Run the window test ( among the quick access buttons). Give a price BT. Select the different values in the Combo Box control and click "Calculate". Our window operates properly now. However, instead of using a formula 3 times to calculate the price, a procedure can be used to perform this calculation . ▶ Close the test window to go back to the code editor. Creating and using a procedure ▶ To create the procedure for calculating the amount IOT: 1. Click the window background. 2. Display the events associated with the window (F2). 3.  In the code editor, on the "Code" pane found in the ribbon, in the "Procedures" group, expand "New" and select "New local procedure". 4.  In the window that is displayed, type the name of local procedure ("Calc_IOT") and validate ("Add" button). 5.  The new procedure local to the window is automatically created and its code is displayed in the code editor. 6. Write the following WLanguage code: PROCEDURE Calc_IOT(PriceBT, VATRate) cyIOT is currency cyIOT = PriceBT * (1 + VATRate/100) RESULT cyIOT Let’s take a look at this WLanguage code: • The Calc_IOT procedure expects 2 parameters: the price before tax and the VAT rate. • This procedure declares a currency variable. This variable is used to store the calculated price IOT. • This procedure calculates the price IOT and returns the calculated value. 7. Close the code window (click X at the top right corner of code editor). Remark When creating a procedure, comments are automatically generated BEFORE the procedure code. 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.

RkJQdWJsaXNoZXIy NDQ0OA==