The information in this article applies to:
- Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a
- Microsoft FoxPro for MS-DOS, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a
SUMMARY
A mover dialog box is an object you can use to move items from one list
object to another to make selections from available choices. FoxPro does
not have a mover dialog box option to choose when making a screen, but you
can use the techniques presented in this article to simulate a mover dialog
box in FoxPro.
MORE INFORMATION
This example of a mover dialog box can be created once but used over and
over throughout all of your applications. The GENSCRN generated code will
be a procedure that accepts three parameters: cTitle, acChoices and
acSelected.
- cTitle is a character expression that will be used for the window title
of the dialog box.
- acChoices is a one-dimensional array of character values representing
the available choices from which the user may select.
- acSelected is a one-dimensional array, the same size as acChoices, but
initialized with null characters (SPACE(0)) that will contain a list of
the selected choices.
When the Mover Dialog Box is run, it will determine if any choices have
already been placed in the "selected list" and mark those choices as
unavailable in the list of choices. As items are selected from the list of
choices, they will become unavailable, unless that item is moved back.
Steps to Create Mover Dialog Box
- Create a screen in FoxPro. On the left side of the screen, create a
list box for the variable m.nChoice from an array called acChoices.
This list box should only take up the left 2/5's of the screen. In the
Valid Code Snippet, place this code:
IF m.nChoice # 0
IF LEFT(acChoices[m.nChoice],1) # "\"
m.nSelected = m.nSelected + 1
m.nSelect = m.nSelected
acSelected[m.nSelected] = acChoices[m.nChoice]
acChoices[m.nChoice] = "\" + acChoices[m.nChoice]
SHOW GETS
SHOW GET nAction, 1 ENABLED
SHOW GET nAction, 2 ENABLED
IF m.nSelected = 0
SHOW GET nAction, 3 DISABLED
SHOW GET nAction, 4 DISABLED
ELSE
SHOW GET nAction, 3 ENABLED
SHOW GET nAction, 4 ENABLED
ENDIF
ENDIF
ENDIF
- On the right side of the screen, create another list box for the
variable m.nSelect from an array called acSelected. This list box
should only take up the right 2/5's of the screen. In the Valid Code
Snippet, place this code:
IF m.nSelect # 0
IF ! EMPTY(acSelected[m.nSelect])
m.Value = acSelected[m.nSelect]
m.nSelected = m.nSelected - 1
=ADEL(acSelected,m.nSelect)
acSelected[ALEN(acSelected)] = ""
x = ASCAN(acChoices,"\"+m.Value)
acChoices[x] = substr(acChoices[x],2)
SHOW GETS
SHOW GET nAction, 1 ENABLED
SHOW GET nAction, 2 ENABLED
IF m.nSelected = 0
SHOW GET nAction, 3 DISABLED
SHOW GET nAction, 4 DISABLED
ELSE
SHOW GET nAction, 3 ENABLED
SHOW GET nAction, 4 ENABLED
ENDIF
ENDIF
ENDIF
- In the middle of the screen, create a vertical, four-button push button
set for the variable nAction. The buttons should be labeled: Select,
Select All, Deselect, Deselect All. In the Valid Code Snippet, place
this code:
DO CASE
CASE nAction = 1 && Select one
IF m.nChoice # 0
IF LEFT(acChoices[m.nChoice],1) # "\"
m.nSelected = m.nSelected + 1
m.nSelect = m.nSelected
acSelected[m.nSelected] = acChoices[m.nChoice]
acChoices[m.nChoice] = "\" + acChoices[m.nChoice]
SHOW GETS
IF m.nSelected = ALEN(acSelected)
SHOW GET nAction, 1 DISABLED
SHOW GET nAction, 2 DISABLED
ELSE
SHOW GET nAction, 1 ENABLED
SHOW GET nAction, 2 ENABLED
ENDIF
SHOW GET nAction, 3 ENABLED
SHOW GET nAction, 4 ENABLED
ENDIF
ENDIF
CASE nAction = 2 && Select All
=ACOPY(laChoices, acSelected)
=ACOPY(laChoices, acChoices)
FOR x = 1 to ALEN(acChoices)
acChoices[x] = "\" + acChoices[x]
ENDFOR
m.nSelected = ALEN(acChoices)
m.nSelect = 1
m.nChoice = 1
SHOW GETS
SHOW GET nAction, 1 DISABLED
SHOW GET nAction, 2 DISABLED
SHOW GET nAction, 3 ENABLED
SHOW GET nAction, 4 ENABLED
CASE nAction = 3 && Deselect one
IF m.nSelect # 0
IF ! EMPTY(acSelected[m.nSelect])
m.Value = acSelected[m.nSelect]
m.nSelected = m.nSelected - 1
=ADEL(acSelected,m.nSelect)
acSelected[ALEN(acSelected)] = ""
x = ASCAN(acChoices,"\"+m.Value)
acChoices[x] = SUBSTR(acChoices[x],2)
SHOW GETS
SHOW GET nAction, 1 ENABLED
SHOW GET nAction, 2 ENABLED
IF m.nSelected = 0
SHOW GET nAction, 3 DISABLED
SHOW GET nAction, 4 DISABLED
ELSE
SHOW GET nAction, 3 ENABLED
SHOW GET nAction, 4 ENABLED
ENDIF
ENDIF
ENDIF
CASE nAction = 4 && Deselect All
=ACOPY(laChoices, acChoices)
STORE "" TO acSelected
m.nSelected = 0
m.nSelect = 0
m.nChoice = 0
SHOW GETS
SHOW GET nAction, 1 ENABLED
SHOW GET nAction, 2 ENABLED
SHOW GET nAction, 3 DISABLED
SHOW GET nAction, 4 DISABLED
ENDCASE
- At the bottom of the screen, create a centered, horizontal, two-button
push button set for the variable m.nResult. The buttons should be
labeled: OK and Cancel. The "Terminate READ On Selection" check box
should also be selected. In the Valid Code Snippet, place this code:
IF m.nResult = 2
=ACOPY(laChoices, acChoices)
=ACOPY(laSelected, acSelected)
ENDIF
- In the Screen Setup Code Snippet, place this code:
#SECTION1
Parameters cTitle, acChoices, acSelected
Private nChoices, nSelected, nChoice, nSelect, nAction, nResult, x
STORE 0 TO nChoices, nSelected, nAction, nResult
=ACOPY(acChoices, laChoices)
=ACOPY(acSelected, laSelected)
FOR x = 1 TO ALEN(acChoices)
nChoices = nChoices + IIF(EMPTY(acChoices[x]),0,1)
IF ASCAN(acSelected,acChoices[x]) # 0
acChoices[x] = "\" + acChoices[x]
ENDIF
ENDFOR
FOR x = 1 TO ALEN(acSelected)
nSelected = nSelected + IIF(EMPTY(acSelected[x]),0,1)
ENDFOR
- In the "On Screen Entry (When)" Code Snippet, place this code:
IF m.nSelected = 0
SHOW GET nAction, 3 DISABLED
SHOW GET nAction, 4 DISABLED
ELSE
SHOW GET nAction, 3 ENABLED
SHOW GET nAction, 4 ENABLED
ENDIF
RETURN .t.
- Under the Screen Layout dialog box, enter the screen title as &cTitle.
and enter the screen name as Selector. Select the Position - Center
check box so that the dialog box will always be centered on the screen.
- Save the screen as Mover.Scx and generate the screen program. You may
use the following as a test program:
CLEAR
? "loading customer names ..."
USE c:\fpw26\tutorial\customer
SET FILTER TO recno()%10 = 0
COPY TO ARRAY aChoices FIELD company
ASORT(aChoices)
USE
CLEAR
DIMENSION aSelected[ ALEN(aChoices,1) ]
aSelected = SPACE(0)
DO mover.spr WITH "Select Company", aChoices, aSelected
CLEAR
? "You chose:"
FOR x = 1 TO ALEN(aSelected)
IF ! EMPTY(aSelected[x])
? x, aSelected[x]
ENDIF
ENDFOR
|