Tuto WEBDEV 25

Part 13: The WLanguage basics 467 6. Write the following code: PROCEDURE Calc_IOT(PriceBT, VATRate) cyIOT is currency cyIOT = PriceBT * (1 + VATRate/100) RESULT cyIOT Let’s study this 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 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. ▶ All you have to do is call the procedure from the Button control. 1. Select the "Calculate" Button control. 2. Display the events associated with the control (press F2, for example). 3. Replace the existing WLanguage code with the following code: 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 WLanguage code calls the Calc_IOT procedure to calculate the amount IOT. Two parameters are passed in parameter: the price BT and the VAT rate. The result returned by the procedure is assigned to the EDT_Price_IOT control. ▶ Let’s now run the page test: 1. Run the page test ( among the quick access buttons). Give a price BT. Select the different values in the Combo Box control and click the "Calculate" button. 2.  The amount BT is displayed. 3. Close the test page.

RkJQdWJsaXNoZXIy NDQ0OA==