Custom calculation in BUFFER-VALUE ?

-Zigo-

Member
Hi everyone,

I hope someone can help me. I have a dynamic browser showing a dynamic query on a dynamic temp-table. Is there a way to assign a calculated value into a buffer value indirectly?

For example, say I have this code:

Code:
CREATE TEMP-TABLE httPlayerStatSeason.
httPlayerStatSeason:CREATE-LIKE(BUFFER PlayerStatSeason:HANDLE).
httPlayerStatSeason:ADD-NEW-FIELD("PointsMinusBonus","INT").
httPlayerStatSeason:TEMP-TABLE-PREPARE("PlayerStatSeason").

hDefaultBuffer = httPlayerStatSeason:DEFAULT-BUFFER-HANDLE.

FOR EACH PlayerStatSeason NO-LOCK:
    hDefaultBuffer:BUFFER-CREATE.
    hDefaultBuffer:BUFFER-COPY(BUFFER PlayerStatSeason:HANDLE).
    hDefaultBuffer:BUFFER-FIELD("PointsMinusBonus"):BUFFER-VALUE = PlayerStatSeason.Points - PlayerStatSeason.Bonus.
END.
This works fine, showing the calculation of (points - bonus) in a column in my browser.

However, what I want to do is create custom calculations against any fields in my PlayerStatSeason table and store the calculation string in another table, so that I can display their results in my browser.

For example, say I have a table CustomCalc with a field CalcName = "PointsMinusBonus" and CalcString = "PlayerStatSeason.Points - PlayerStatSeason.Bonus" (i.e. the same calculation as above). I want my code to effectively be:

Code:
FOR EACH PlayerStatSeason NO-LOCK:
    hDefaultBuffer:BUFFER-CREATE.
    hDefaultBuffer:BUFFER-COPY(BUFFER PlayerStatSeason:HANDLE).

    FIND CustomCalc WHERE CalcName = "PointsMinusBonus" NO-LOCK.

    hDefaultBuffer:BUFFER-FIELD("PointsMinusBonus"):BUFFER-VALUE = CustomCalc.CalcString.
END.
Is this possible in any way?
 

D.Cook

Member
As far as I'm aware, there's no function to dynamically evaluate a string as code (like the eval function in some other languages). And I can't imagine any other way to do this sorry..
 

-Zigo-

Member
Thanks, I thought as much.

I can think of a 'dirty' way of doing it, involving writing the calculation code out to a .p file as a function, then running it persistently and invoking the function dynamically. I don't like that method though, and would prefer to do it in a more elegant way if possible.
 

Stefan

Well-Known Member
I think Progress Knowledge base ID P39990 "How to evaluate a math formula stored in a character variable?" may be usable.
 

GregTomkins

Active Member
Hey, that's a good one! Using a fake dynamic query to evaluate a character variable that contains a math expression. Makes me glad that I still check PT from time to time.
 
Top