Tuto WINDEV 25
164 Part 4: Full application with data 15. Select the Combo Box control and resize it (via the handles) in order for the full customer name to be displayed. ▶ To create the Button control to find customers: 1. Create a Button control: on the "Creation" pane, in the "Usual controls" group, click . 2. Position the Button control beside the Combo Box that was just created. 3. This control is named "BTN_ExactMatchSearch" and its caption is "Exact-match search". 4. If necessary, adjust the size of the control so that the caption is displayed properly in the control. 5. Write the following WLanguage code in the "Click" event of the control: // Finds the customer from his identifier HReadSeekFirst(Customer, CustomerID, COMBO_Customer) IF HFound(Customer) THEN // Displays the customer data FileToScreen() END 6. Let’s take a look at this WLanguage code: • HReadSeekFirst is used to perform an exact-match search. In this example, the search is performed on the Customer data file and on the CustomerID item. The sought value corresponds to the last parameter of the function. Here, the sought value corresponds to the value selected in the Combo Box. This value is obtained by using the name of the Combo Box control (COMBO_Customer). • HFound is used to check the search result. If HFound returns True, a value was found ; if HFound returns False, no value was found. Any record found is read: it becomes the current record in the data file. • In this code, if the record was found, it is displayed by FileToScreen . Remark FileToScreen and ScreenToFile perform the reverse operation: the data found in the file items is displayed in the corresponding controls. 7. Close the code editor. 8. Save the window (Ctrl + S).
Made with FlippingBook
RkJQdWJsaXNoZXIy NDQ0OA==