Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stacking variables from form 1

Status
Not open for further replies.

dweis

IS-IT--Management
Apr 17, 2001
48
US
Hi all. I'm relatively new to VFP7 & am converting old 2.6a code. Was wondering if it would be possible to take a main form with command buttons, pass parameters to those buttons & save the old values so when the user exits the routine, the buttons are reset to their original values. I have accomplished this by the code below, however what I can't figure is how to work it if there is program nesting. Example, I click "View" and that does inv_view, well inv_view has buttons I can click to do yet another proc, inv_detail. What I have can save the button config from main to inv_view & restore them when a user exits. What I need is to be able to save the 1st set of variables & also the second set so I can exit inv_detail & the buttons will return to the inv_view set, exit that & they return to the main set. Sorry if this is confusing.

Proc mk_form
parameters lcd2, lcd3, lcd4, lcd5, lt_1, lt_2, lt_3, lt_4
Public lcdw2, lcdw3, lcdw4, lcdw5, lt1, lt2, lt3, lt4

lcdw2 = lcd2
lcdw3 = lcd3
lcdw4 = lcd4
lcdw5 = lcd5

do form history name hist linked with lcdw2, lcdw3, lcdw4, lcdw5, lt1, lt2, lt3, lt4, lt5

The init event of the form paints the buttons so to speak. The Proc reads
do mk_form with prg1, prg2, prg3, prg4, label1, label2, label3, label4

The end of prg1 reads the same way, do mk_form with ...
then return.

Sorry for the length. Do I need to use an array? If so, can you provide an example as I'm green when it comes to those.
Also, I don't really want to use a toolbar but if there's not other way then I'll have to give it a whirl. My customers are used to the command buttons. I relate this to pushing keys & then popping them in the old 2.6 code. I was able to push levels of custom keystrokes & revert by popping the keys off the stack. Any help would be appreciated. Thanks!
 
The best way probably IS to use a stack. Just DIMENSION an array in your top level program and define a variable as the pointer to the top of the stack.

Write PushButtons and PopButtons routines that take the parameters, and which tickle the buttons' .Caption properties (you might also want to stick the commands to execute in each button's .Tag property).

You'll have to store both the Button Captions and the Command to execute in the same row of the array (or in two parallel arrays) since VFP doesn't do 3 dimensioned arrays.
 
Thanks for the input. Could you possibly supply an example of the array? Should I use the calling program as the variable to point to the line of the array?
 
Header File (MAIN.H):
#DEFINE STACK_MAX 50
#DEFINE BUTTON_BAR_COUNT 5
**************************************************
Main program (MAIN.PRG):
#INCLUDE MAIN.H
PUBLIC gaStack, gnStack, goButtonBar
DIMENSION gaStack[STACK_MAX,BUTTON_BAR_COUNT*2]
gnStack = 0

... Create your button bar and store a reference
... in goButtonBar


PROCEDURE PushButtonStack( pcNewB1Cap, pcNewB1Cmd, pcNewB2Cap, pcNewB2Cmd .... )
gnStack = gnStack+1
WITH goButtonBar
gaStack[gnStack,1] = .Command1.Caption
gaStack[gnStack,2] = .Command1.Tag
gaStack[gnStack,3] = .Command2.Caption
gaStack[gnStack,4] = .Command2.Tag
... etc. ...
.Command1.Caption = pcNewB1Cap
.Command1.Tag = pcNewB1Cmd
.Command2.Caption = pcNewB2Cap
.Command2.Tag = pcNewB2Cmd
... etc. ...
ENDWITH
RETURN

PROCEDURE PopButtonStack
if gnStack>0
WITH goButtonBar
.Command1.Caption = gaStack[gnStack,1]
.Command1.Tag = gaStack[gnStack,2]
.Command2.Caption = gaStack[gnStack,3]
.Command2.Tag = gaStack[gnStack,4]
... etc. ...
ENDWITH
endif
***********************************
In each Click event of the buttons, Command1, etc. in
goButtonBar, put this:
IF NOT EMPTY(THIS.Tag)
LOCAL lcCommand
lcCommand = THIS.Tag
&lcCommand
ENDIF
 
Thank you very much for your assistance. I'll give this a try and see how it goes. Definately an A++ for response & sampling. Thanks again.

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top