How to retrieve the account balance in scm?

Derek Atkins derek at ihtfp.com
Mon Dec 26 09:04:07 EST 2011


Hi,

On Mon, December 26, 2011 8:02 am, casi wrote:
> Hi,
>
> GnuCash 2.4.7, on Ubuntu 11.10
>
> trying to get familiar with customizing reports directly in Scheme, I
> managed to get into the language deep enough to get the clou out of
> hello-world.scm (working and playing around with my private copy).
>
> hello-world.scm tells you a lot about how to set and retreive options
> and values for a report, but it does not tell you much about how to make
> use of them.
>
> Starting with the very basic (as I thought) I tried to read from the
> standard reports how to do this - but this is not really obvious to me
> (I am looking at account-summary.scm and cash-flow.scm, maybe not
> clever?).
>
> Finally, I got down to calling
> "(gnc:account-get-balance-at-date acct date-val #f)"
> and the debug print out shows the return value as
> "#<<gnc-numeric> num: -53065 denom: 100>"
> and here I get stuck as I don't find any syntax explanation for
> "#<...>".
>
> (Well, I do understand that the account balance is -53065/100 ->
> -530.65, which is correct.)
>
> I tried to interpret "#<<gnc-numeric> num: -53065 denom: 100>" as
> - string
> - list
> - vector
> (- even tried "numerator ...")
> neither of which seems to work (and unfortunately gnucash.trace only
> shows what input type is expected, but not what it actually got).

You should interpret it as a gnc-numeric (which is exactly what it's
telling you it is).  You can use the gnc-numeric operations or, as shown
in other reports, a commodity-collector, to sum up your values.  Then you
can put them into number-column tables to output them.

> So here comes my question:
> How can I get the numerical account balance value from "#<<gnc-numeric>
> num: -53065 denom: 100>" ?

You HAVE the account balance, in the form of a gnc-numeric.

> If there is even a smarter way to get to the same result, feel welcome
> to give me that hint :-)

You don't say what you are trying to do with the balance, so I don't know
if there is a "smarter way to get the same result".  The function you
called is generally the correct one to get the balance-as-of-date.

> Thx and advance,
> Carsten

> Please remember to CC this list on all your replies.
> You can do this by using Reply-To-List or Reply-All.

-derek

-- 
       Derek Atkins                 617-623-3745
       derek at ihtfp.com             www.ihtfp.com
       Computer and Internet Security Consultant



More information about the gnucash-user mailing list