Tuto WINDEV 25
Part 2: The WLanguage basics 53 Comparing two strings ▶ To create a Button control to compare two strings: 1. On the "Creation" pane, in the "Usual controls" group, click . 2. Click the location where the control will be created (for example, to the right of the existing Button control). 3. Click the control that was just created. The text displayed in the button becomes editable. Type the caption: "Compare two strings". 4. Press Enter to validate the input. 5. Adapt the control size. 6. Display the events associated with the control (F2). 7. In the "Click" event of the control, write the following WLanguage code: sStringToCompare is string = "WINDEV" IF EDT_Text ~= sStringToCompare THEN Info("The displayed text corresponds to " + sStringToCompare) ELSE Info("The displayed text does not correspond to " + ... sStringToCompare) END Let’s take a look at this WLanguage code: • A String variable is declared. This variable contains the string to compare. • The ~= operator corresponds to a flexible equality. This operator is used to perform a comparison while ignoring the case, the spaces found before and after the string and the accented characters. • If the comparison is true, the edit control corresponds to the word found in the string to compare regardless of the case used. 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. Click "Compare two strings". A message indicates that the comparison is not correct. 3. Validate the message. 4. In the edit control, type "WINDEV" in uppercase characters and click "Compare two strings". The WINDEV word is found. Validate the message. 5. Modify the content of edit control (by replacing WINDEV by WINDEV for example) and click "Compare two strings". The WINDEV word is also found. Validate the message. 6. Close the window.
Made with FlippingBook
RkJQdWJsaXNoZXIy NDQ0OA==