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

Calculate feilds on screen

Status
Not open for further replies.

GDJP

Technical User
Oct 16, 2001
9
CA
I am struggling to write the proper code lines to have two (or more) feilds perform a calculation on the screen as the user enters the required infomation.

i.e. 5,000 (feild1) plus 500 (field2) = 5,500 (new feild for results)

I have figured it out to the point that the calculations work fine but only when the file is closed (so users would have to enter info into the first two fields then close the file and open it again the see the results.

Is there a way to do these calculations on the fly showing the results on the screen and if so can I use the same method for more complex calculations (percentages etc)?

This is probably a realy basic problem but I am lost!

Thanks in advance

Grant
 
I have used DB3+ and can only part with that knowledge since you didn't mention which ver you were using.

In the PRG file I'd create two memory variables first then display the calcs. and ask if to save/store the data.

If YES then append blank and insert memory variables into the fields. Otherwise, I'll just erase the memory variables to provide more room.

--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Sorry, I forgot.

If you are using DB3+ or would like to see an example, let me know.

--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Thanks for the pointer which I think I can follow. I am using dBase 4 (not sure of which version) which I inherited (hence my struggle).

I think the code would be a help and would be greatful if you can let me see it.

Thanks for the help

Grant

 
Sorry it took so long. Wife tied up the computer with her "e-chatlines" (darn Messengers). Anyway, it gave me some time to go through my archives.

I've found an old PRG file. With a little modification, I think this is ruffly what you're looking for.


PREP:
copy following code to a PRG file to run from.
create a database (I've used ZTEST.DBF in this example).
create fields with the following info:

[tt] NAME TYPE SIZE DEC
Field1 Num 5 0
Field2 Num 5 0
Answers Num 6 0
[/tt]


CODE: (As Follows)

*------------------------------------------------------------*
SET TALK OFF
SET ECHO OFF
SET CONFIRM OFF
SET CENTURY ON

*** ENVIRO. VARIABLES ***
TAXNO = 0
AUTOPASS = 0
CHOICE = 0
YN = " "

*** MAIN PROGRAM ***
USE ZTest.dbf
clear
DO WHILE .T.
@ 11, 10 SAY "Enter 1ST number (1 - 9999) --> " GET TAXNO PICTURE "9999"
@ 13, 10 SAY "Enter 2ND number (1 - 9999) --> " GET AUTOPASS PICTURE "9999"
@ 14, 5 TO 14, 60 DOUBLE
READ
CHOICE = TAXNO + AUTOPASS
@ 15, 10 SAY "This is the answer when added: "
?? CHOICE
?
?
wait "Save data now? (Y/n) --> " to YN
IF UPPER(YN) <> &quot;N&quot; THEN
GO BOTT
APPEND BLANK
REPLACE Field1 with TAXNO
REPLACE Field2 with AUTOPASS
REPLACE Answers with CHOICE
? &quot;---- Data has been saved&quot;
ENDIF
TAXNO = 0
AUTOPASS = 0
CHOICE = 0
YN = &quot; &quot;
?
wait &quot;Do you have another addition problem? (Y/n) --> &quot; to YN
IF UPPER(YN) = &quot;N&quot; THEN
exit
ENDIF
LOOP
ENDDO

clear
wait &quot;Want to see stored data? (Y/n) --> &quot; to YN
IF UPPER(YN) <> &quot;N&quot; THEN
go top
disp all
ENDIF
CLOSE all * DATABASES
?
? &quot;---- Bye Bye&quot;
return
*------------------------------------------------------------*

Any questions, let us know.
Good Luck,
--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Well I guess it worked.
It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Sorry!! Out of town with Family for a few days and could not get to this project. Thanks for the code I think I will be OK now.

Thanks again for the help, much appreciated.
 
Glad you came back and glad to have helped. If you need further info or help just ask.
--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top