Re: Trip Mileage Calculation



I'm sorry I don't have time right now to elaborate on this, but you might also consider use of the GetNthRecord() function through a self-relationship of all records to check the previous record's entry.

Bill wrote:
In article <IPBok.709$EL2.70@trnddc01>, "PghOPS" <dan@xxxxxxxxx> wrote:

I am trying to setup a vehicle use log.

I need to calculate trip mileage for each use of the vehicle. I have a starting mileage, ending mileage and trip mileage field.

So: ending mileage, minus starting mileage equals trip mileage.

How do I make each trip use the ending mileage of the previous trip for the starting mileage of the current trip to perform the calculation to obtain the trip mileage?

Trip 1
Ending Mileage = 150
Starting Mileage = 100
Trip Mileage = 50

Trip 2
Ending Mileage = 160
Starting Mileage = 150
Trip Mileage = 10

Thanks in advance for any help or suggestions!

One way is to use a script that sets the field Starting Mileage based on the Ending Mileage of the last trip.

Use that script to create a new Trip record.

You can put a pushbutton in the layout to call the script when you want to make a new record.

First, I assume you have a trip date field, or may a starting and ending date. You can use that in the script.

The script cold be something like this:

Enter Browse mode
Show all records
Sort records [Date; descending order]
Go to Record/Request [First]
Set variable [$StartMile; Ending Mileage]
New Record/Request
Set field [Starting Mileage; $StartMile]

You don't say what version of Filemaker you are using. The foregoing script is based on using script variables, which can only be done in fairly recent versions (FM 8 and later, I think). If you are using and earlier version that does not have script variables, then you can use a global field to store the value of ending mileage of the last trip. Then the script would have a step like this:

Set Field [gStartMile; Ending Mileage]


in place of the step that sets the script variable, and a step

Set field [Starting Mileage; gStartMile]

in place of the step that sets the startig mileage based on the variable.


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Howard Schlossberg
FM Professional Solutions, Inc. Los Angeles

FileMaker 8 Certified Developer
Member, FileMaker Business Alliance
.


Loading