Announcement

Collapse
No announcement yet.

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

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    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.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      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.

      Comment


      • #4
        Originally posted by chersey View Post
        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
        Last edited by aducom; 05-15-2013, 09:53 AM.
        Albert Drent
        aducom software netherlands
        scriptcase partner, reseller, support and (turn-key) development
        www.scriptcase.eu / www.scriptcase.nl

        Comment


        • #5
          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

          Comment


          • #6
            You're right of course. Changed it.
            Albert Drent
            aducom software netherlands
            scriptcase partner, reseller, support and (turn-key) development
            www.scriptcase.eu / www.scriptcase.nl

            Comment

            Working...
            X