Tuto WINDEV 25
52 Part 2: The WLanguage basics Finding a string ▶ To create a Button control to search for a string: 1. On the "Creation" pane, in the "Usual controls" group, click . 2. Click the location where the 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. Adapt the control size. 6. Display the events associated with the control (F2). 7. Write the following code in the "Click" WLanguage event: sSoughtString is string = "WINDEV" 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 take a look at this WLanguage 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. • If Position returns 0, it means that the sought string was not found. A message is displayed by Info . 8. Close the code window (click X at the top right corner of code editor). ▶ Let’s now run the window test: 1. Click among the quick access buttons (or press F9). 2. The created window is saved and started in execution. Click "Find a string". The WINDEV word is found. 3. Modify the content of edit control (by replacing WINDEV by WD for example) and click "Find a string". The WINDEV word is not found. 4. Close the window.
Made with FlippingBook
RkJQdWJsaXNoZXIy NDQ0OA==