ID: Q104258
2.00 2.50 2.50a | 2.50 2.50a 3.00
MS-DOS | WINDOWS
The information in this article applies to:
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.
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.
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
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