Microsoft KB Archive/104258

From BetaArchive Wiki

Sample Code for Creating Multiple-Selection GET List Box

ID: Q104258

2.00 2.50 2.50a | 2.50 2.50a 3.00

MS-DOS          | WINDOWS

The information in this article applies to:

  • Microsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a

SUMMARY

FoxPro does not include a multiple-selection GET object that is activated with a READ command. However, you can create a multiple-selection list object by storing the information that is selected in the VALID clause for the list object, as explained below.

MORE INFORMATION

There are several different methods of creating a multiple-selection list object. The following example demonstrates how to make selections in an array. (In the example, the array is called "test".) The selections are marked by a check mark [CHR(251)], and then the selection is displayed when the Done button is chosen. The VALID routine for the push button sorts the array and stores the selected options in a variable. All options that were selected are stored in the "checked" variable.

Notes

  • If you use a two-column array, most statements in this code need to refer to TEST[i,1] if the information you want is in the first column.
  • Under Windows, you must use the FoxPro for Windows font. The default font for a list box is MS Sans Serif, which does not display a check mark for CHR(251).

    CLOSE DATABASE CLEAR

    USE tutorial\customer *** Create array test to store the field CNO from database COPY TO ARRAY test FIELDS cno *** Store a space as the first character of every element of the *** array. FOR i = 1 TO ALEN(test)

          test(i) = " " + test(i)

    ENDFOR *** Initialize variables

       selected = 0       && Variable to store number of selected items
       checked = " "      && Variable to store selected items
    
       DEFINE WINDOW test FROM 0,0 TO 17,20 TITLE "Test Application"
       MOVE WINDOW test CENTER
       ACTIVATE WINDOW test
       @ 2,2 GET choice FROM test DEFAULT 1 SIZE 10,10 ;
          VALID myval()
       @ 14,2 GET button PICTURE "@* Done" VALID done() DEFAULT 1
       READ CYCLE
       RELEASE WINDOW test
    
       *** VALID procedure for list box
       PROCEDURE myval
          *** Test to see if item has been selected by checking first
          *** character
          IF SUBSTR(test(choice),1,1) = " "
             *** Store check mark as first character of array element
             *** when item is selected.
             test(choice) = CHR(251) + SUBSTR(test(choice),2)
             *** Increment number of items selected
             selected = selected + 1
          ELSE
             *** Store a space as first character of array element
             *** to unselect item.
             test(choice) = " " + SUBSTR(test(choice),2,LEN(test(choice))-1)
             *** Decrement number if items selected
             selected = selected - 1
          ENDIF
          *** Reset current object to list box
          _CUROBJ = OBJNUM(choice)
    
       *** VALID procedure for Done push button
       PROCEDURE done
          *** Sort selected items to top if array
          result = ASORT(test,1,ALEN(test),1)
          *** Store selected items to variable "checked"
          FOR i = 1 to selected
          *** Substitute any desired code to store selected options
              checked = SUBSTR(test(i),2) + " " + checked
          ENDFOR
          RELEASE test
          *** Display selected options
          WAIT WINDOW "You selected " + checked
          CLEAR READ
    

Additional reference words: VFoxWin 3.00 FoxDos FoxWin 2.00 2.50 2.50a list popup multi select multi-select multiselect multiseletion KBCategory: KBSubcategory: FxprgGeneral

Keywords          : kbcode FxprgGeneral 
Version           : 2.00 2.50 2.50a | 2.50 2.50a 3.0
Platform          : MS-DOS WINDOWS

Last Reviewed: May 22, 1998
© 1999 Microsoft Corporation. All rights reserved. Terms of Use.