Microsoft KB Archive/104258: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
Line 20: Line 20:
== MORE INFORMATION ==
== 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.
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 ===
=== Notes ===
Line 29: Line 29:
<p>CLOSE DATABASE CLEAR</p>
<p>CLOSE DATABASE CLEAR</p>
<p>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)</p>
<p>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)</p>
<pre>      test(i) = &quot; &quot; + test(i)</pre>
<pre>      test(i) = " " + test(i)</pre>
<p>ENDFOR *** Initialize variables</p>
<p>ENDFOR *** Initialize variables</p>
<pre>  selected = 0      &amp;&amp; Variable to store number of selected items
<pre>  selected = 0      &amp;&amp; Variable to store number of selected items
   checked = &quot; &quot;     &amp;&amp; Variable to store selected items
   checked = " "     &amp;&amp; Variable to store selected items


   DEFINE WINDOW test FROM 0,0 TO 17,20 TITLE &quot;Test Application&quot;
   DEFINE WINDOW test FROM 0,0 TO 17,20 TITLE "Test Application"
   MOVE WINDOW test CENTER
   MOVE WINDOW test CENTER
   ACTIVATE WINDOW test
   ACTIVATE WINDOW test
   @ 2,2 GET choice FROM test DEFAULT 1 SIZE 10,10 ;
   @ 2,2 GET choice FROM test DEFAULT 1 SIZE 10,10 ;
       VALID myval()
       VALID myval()
   @ 14,2 GET button PICTURE &quot;@* Done&quot; VALID done() DEFAULT 1
   @ 14,2 GET button PICTURE "@* Done" VALID done() DEFAULT 1
   READ CYCLE
   READ CYCLE
   RELEASE WINDOW test
   RELEASE WINDOW test
Line 47: Line 47:
       *** Test to see if item has been selected by checking first
       *** Test to see if item has been selected by checking first
       *** character
       *** character
       IF SUBSTR(test(choice),1,1) = &quot; &quot;
       IF SUBSTR(test(choice),1,1) = " "
         *** Store check mark as first character of array element
         *** Store check mark as first character of array element
         *** when item is selected.
         *** when item is selected.
Line 56: Line 56:
         *** Store a space as first character of array element
         *** Store a space as first character of array element
         *** to unselect item.
         *** to unselect item.
         test(choice) = &quot; &quot; + SUBSTR(test(choice),2,LEN(test(choice))-1)
         test(choice) = " " + SUBSTR(test(choice),2,LEN(test(choice))-1)
         *** Decrement number if items selected
         *** Decrement number if items selected
         selected = selected - 1
         selected = selected - 1
Line 67: Line 67:
       *** Sort selected items to top if array
       *** Sort selected items to top if array
       result = ASORT(test,1,ALEN(test),1)
       result = ASORT(test,1,ALEN(test),1)
       *** Store selected items to variable &quot;checked&quot;
       *** Store selected items to variable "checked"
       FOR i = 1 to selected
       FOR i = 1 to selected
       *** Substitute any desired code to store selected options
       *** Substitute any desired code to store selected options
           checked = SUBSTR(test(i),2) + &quot; &quot; + checked
           checked = SUBSTR(test(i),2) + " " + checked
       ENDFOR
       ENDFOR
       RELEASE test
       RELEASE test
       *** Display selected options
       *** Display selected options
       WAIT WINDOW &quot;You selected &quot; + checked
       WAIT WINDOW "You selected " + checked
       CLEAR READ
       CLEAR READ
</pre></li></ul>
</pre></li></ul>

Revision as of 09:35, 20 July 2020

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.