Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Summing in a grid
Message
 
To
05/01/2001 14:28:18
Cgi Int
p2 Software Consultancy
Mumbai, India
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00459984
Message ID:
00459989
Views:
16
>what is the best way to total up columns in a grid while entering in information at the same time.

The way I do it is put some code in the InteractiveChange() event of the control where the values will be entered, in my case I always use spinners. In that code I make sure the value just entered was committed to the underlying cursor or table or whatever controls the grid. Then I sum up the values for that column using a simple "sum Field to lnVar" command. Before you do the sum command you need to save the recno() to a variable so you can go back to that record after the sum command because the sum command will move the record pointer.

Here's some code that I use:
SELE ztemp2 &&control cursor
IF !BOF() AND !EOF()
	lnRecno=RECNO()
	REPL ztemp2.prcnt2 WITH THIS.VALUE &&commit changes
	SUM ztemp2.prcnt2 TO lnValue
	IF lnValue<=100  && sum can't be over 100
		THIS.PARENT.PARENT.PARENT.txtTotal2.VALUE = ROUND(lnValue,1)  &&puts the sum in a textbox below the grid
		THIS.PARENT.PARENT.PARENT.cmdAddRec.ENABLED=.T.
	ELSE
		THIS.VALUE = THIS.VALUE -(lnValue-100)
		THIS.PARENT.PARENT.PARENT.txtTotal2.VALUE = 100.0
		THIS.PARENT.PARENT.PARENT.cmdAddRec.ENABLED=.F.
	ENDIF
	GO lnRecno
ENDIF
Rip Ryness
International Falls, MN
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform