Tuto WEBDEV 25

436 Part 13: The WLanguage basics Finding a string ▶ To create the "Find a string" Button control: 1. On the "Creation" pane, in the "Usual controls" group, click . 2. Click the location where the Button control will be created (below the edit control for example). 3. Click the control that was just created. The text displayed in the control becomes editable. Type the caption: "Find a string". 4. Press Enter to validate the input. 5. Display the events associated with the Button control (press F2). 6. Write the following code in the server "Click" event of the button: sSoughtString is string = "WEBDEV" nPos is int nPos = Position(EDT_Text, sSoughtString) IF nPos = 0 THEN Info(sSoughtString + " not found in the text") ELSE Info(sSoughtString + " found at position " + nPos) END Let’s study this code: • Two variables are declared: a String variable corresponding to the sought string and an Integer variable corresponding to the position of sought string. • Position is used to find a string inside another one. In our example, we search for the content of sSoughtString in the content of EDT_Text control. • The IF statement is used to check the result of Position . This type of statement will be presented later in this section on WLanguage. • If Position returns 0, it means that the sought string was not found. A message is displayed by Info . 7. Close the code window (click X at the top right corner of code editor).

RkJQdWJsaXNoZXIy NDQ0OA==