[Solved] Currency variables in macro

Discuss the spreadsheet application
Post Reply
lorenzo2
Posts: 4
Joined: Tue Jul 15, 2008 8:12 pm

[Solved] Currency variables in macro

Post by lorenzo2 »

I've run across what appears to be an error in the way currency variables are implemented. Or maybe I'm just doing something wrong - if so, I would appreciate advice.

Here's a short little OO macro. (Sorry to post this, but I don't know how else to describe the problem.)

Code: Select all

Sub Main

   Dim oDocument As Object, oSheet As Object, oCell As Object
   
   Dim cost as currency
   Dim total as currency
   
   Dim buy as integer
   
   oDocument = ThisComponent
   oSheet=oDocument.Sheets.getByName("Sheet1")
   
   oCell=oSheet.getCellByPosition(0,0) 'A1
   buy = oCell.getValue   
   
   oCell=oSheet.getCellByPosition(1,0) 'B1
   cost = oCell.getValue  
   total = buy*cost
   
   oCell=oSheet.getCellByPosition(2,0) 'C1
   oCell.setValue(total)
 
End Sub 
As you can see, it doesn't do much: it gets an integer (buy) from cell A1 on Sheet1, gets a currency value (cost) from cell B2, and writes the product of those two numbers (total) in cell C1. (This is distilled from a much more complex macro simply to illustrate the problem.)

Ok, easy enough. Let's enter some numbers in Sheet1. Set A1 to 5 and B1 to 40000. Run the macro, and sure enough, the product (200000) goes into C1.

Now change B1 to 50000 and run the macro again. Whoops! That's a bit wrong! Looks like some kind of overflow with the currency type. (If I change the two currency variables to type long, then it works fine - but, well, I want them to be type currency!)

I'm currently using OO 2.4.1, but the same thing happened earlier, with 2.3.x.

If this is a genuine bug, I'd be glad to submit a trouble report if I can figure out how to do that...

Lorenzo
Last edited by lorenzo2 on Wed Jul 16, 2008 8:16 pm, edited 1 time in total.
OOo 2.4.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: currency variables in macro

Post by Villeroy »

All valid values in Calc are doubles and strings. There are no other types.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
lorenzo2
Posts: 4
Joined: Tue Jul 15, 2008 8:12 pm

Re: currency variables in macro

Post by lorenzo2 »

All valid values in Calc are doubles and strings.


I suppose that's correct - when you get right down to it, it's all just numbers and strings,
and the rest is formatting. My problem really isn't a Calc issue, it's an OOo Basic issue.
I'll post something on that board. Thanks.
OOo 2.4.X on Ms Windows XP
Post Reply