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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FPD26 for DOS - Automatically calculating logical

Status
Not open for further replies.

Foxtech

Programmer
May 26, 2001
66
0
0
CA
Hi experts,

As in windows style I would like to modify the DOS program to make it calculates automatically the TOTAL when finishing to enter the QTY or PRICE for each line.

More precise I don't want to use F9=Calculate key.

Is there any solution or because the limitation in DOS style.

Please help...thanks in advance !!!

FoxTech

Here is an example of the screen:

QTY PRICE
___ _____
___ _____
___ _____
___ _____

TOTAL:

F9=Caculate the total ESC=Exit

Here is the codes:

(TEST999.PRG)

public mqty1, mpice1, mqty2, mprice2, mtotal

mqty1 = 0
mprice1 = 0

mqty2 = 0
mprice2 = 0

mtotal = 0



Do while Lastkey() != 27

on key label F9 do CALTOTAL

Do EntryScreen

Enddo


Procedure EntryScreen

@ 4,67 say 'Qty' color +gr/b
@ 4,71 say 'Price' color +gr/b
@ 14,60 say 'Total:' color +gr/b

@ 20,1 say 'F9=Calculate Total ESC=EXIT' color +gr/b

@ 5,67 GET mqty1 pict "999"
@ 5,71 GET mprice1 PICTURE "99999.99"

@ 7,67 GET mqty2 pict "999"
@ 7,71 GET mprice2 PICTURE "99999.99"

Read
Return


PROCEDURE CALTOTAL
PUSH KEY CLEAR
mtotal = 0
mtotal = (mqty1*mprice1) + (mqty2*mprice2)
@ 14,67 say mtotal pict "99999.99"
Return
 
The following was tested in FoxPro 2.6 for Windows. I do not know if it works in FoxPro for DOS.

You can add a VALID clause to each of the @ GET lines so that the total will be recalculated as the user leaves each of the QTY or PRICE fields.

This shows the revised code:
Code:
@ 5,67  GET mqty1  pict "999" VALID caltotal()
@ 5,71 GET mprice1  PICTURE "99999.99" VALID caltotal()

@ 7,67  GET mqty2  pict "999" VALID caltotal()
@ 7,71  GET mprice2  PICTURE "99999.99" VALID caltotal()

Also, to zero out the total (if the code is run repeatedly) there are several different options. You can add this line right before the DO/ENDDO loop
Code:
do caltotal
or add this line before the first @ GET:
Code:
@ 14,67 say mtotal pict "99999.99"
or simply add
Code:
CLEAR
at the beginning of the program.

Teresa
 
hi Teresas,

Yes, it works in Foxpro for DOS as well.

Thanks again and I'm very appreciated.

A+

Foxtech
 
Foxtech,

You're welcome. I'm glad to hear it worked!

Teresa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top