Navigate back 1 record (row) - get value - return to previous record (row)

In a grid, how let’s say I have 3 rows of data. How could I use data from row 1 to make a calculation for row 2? Somehow in onRecord event go back 1 row, store field to variable, return to previous record and make the calculation using the variable. :frowning:

It depends on what you want to do. Of course you can use onrecord where you store the current record in a global variable to be used on the next record, overwrite the fields with the new current record etc. In php it’s easy to pack the data of an array to be unpacked later on.

It’s not that easy to revert to the previous record but not undoable if you store the keyfield as a global variable and use a custom select in the event to retrieve the data you need.

Finally you can use grouping etc. functions within scriptcase to get things done. Depends on your need.

Thanks Albert. It’s basically a fuel log project. I want to use the mileage entry from the previous record to compare with current mileage and calculate MPG.

MPG=Miles per Gallon? I think I would start by setting up a global variable [glob_mileage] and set that default to -1 in the onscriptinit. Then add a column ‘MPG’ to the grid. Then in the onrecord I would do something like

if([glob_mileage]>=0) {
calculate MPG here
};

[glob_mileage]={mileage}; // new mileage from the database to be used next cycle

Albert… I think you need to move the setting of the global outside the if otherwise it will never become >= 0

if([glob_mileage]>=0) {
calculate MPG here
};
[glob_mileage]={mileage}; // new mileage from the database to be used next cycle

Nick

You’re right of course. Changed it.

@aducom woooow,7 years later i would use your advise… grate! and thanks alot from the future! :D:D:D:D

Yeah, I’m an old guy already :wink: