View Full Version : Help with FoxPro - Calculation of fields in same table
LeMagnifique
05-17-02, 07:32
| Hi there! Ok, i have a question.
I've been doing an application for a taxi company i work for and they requested a pgm in FoxPro...that's sucks cauz i have no fox experience.
ok let's go right into the subject, i need to know how i can substract a the same field in two different records in the same table.
eg:
table fields---------------------------->fuel
ticket # - carID - Date of filling - AMt filled - mileage
-------------------------------------------------------------
100 - 3 - 05/08/02 - 30 liters - 123100 km
101 - 3 - 05/17/02 - 40 liters - 123600 km
ok i need to substract the mileage of the last ticket with the previous one
eg: 123600 -123100 = 500 km
and so on for all added tickets... I've been brain washing my head on this....can't do it.:confused:
i need to know so that i can calculate how many km the car went on 1 gallon of fuel
eg : (20*500)/ 30 = 333.33km
so for 1 gall the car went 333.34 km
Can anybody give suggestions?
:(
Thanks i would really appreciate. |
LeMagnifique
05-18-02, 05:09
I forgot to mention, that i'm a newbie in database programming.
As I explain before,
I need to know if i should include in the above table more fields to contain variables.
eg should i make a field to store the result of the mileage calculation and another for the gallon/mile field.
my problem is that i'm confused about doing a substraction on the last added mileage record with the previous one.:confused:
once i have this issue resolved all the rest should be simple.
eg:
ticket # - idcar- filldate-amtfilled-mileage-totmile-totgal
--------------------------------D---------A
-------------------------------------------B----
----------------------------------------------------C--------E
so milageB - mileageA = C
Then i can do E = [C*20] / D
Ok suggestions on how i can do that in fox? Anyone plz?
:( :o :mad:
| In FoxPro you can use xBase commands like:
go Bottom - select last record of the table
Skip 1 - go next record
Skip -1 go prev record
go Top - go first record
So if the table's name is Cars, then
Private nMileageA, nMileageB
Select 0
Use Cars
go bottom
nMileageA = cars->AMtfilled
Skip -1
nMileageB = cars->AMtfilled
? nMileageA - nMileageB
FoxPro also supports SQL.
HTH, Igor |
vBulletin v3.5.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.