OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Use of Calc functions within a Basic Macro

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
hertfordkc
Newbie
Newbie


Joined: 24 Oct 2006
Posts: 1
Location: NC

PostPosted: Sun Sep 19, 2010 5:16 pm    Post subject: Use of Calc functions within a Basic Macro Reply with quote

I've used MS/Visual Basic and OpenOffice for a for more than a decade. I've reached the point of converting my VB macros to OO. First attempt not going well. Using OO within Ubuntu 10.xx.

Function SetID(Anum, Ayr)
Dim a1,a2,a3,a4,a5 as integer
a1 = Anum * 17
a2 = int(a1/10000) ' most significant two numbers (tens and hundred thousands)
a3 = a1-a2*10000
a4 = Int(a3/100) ' middle two numbers (hundreds and thousands)
a5 = a3 - a4*100 ' ones and tens
a1 = Ayr-Int(ayr/10)*10
a2 = (a2*+a1)*10 + Rand()*9
a1= rand()*9
SetId = RAND()*9 ' a2 +1000*a5+a1*100000
end Function

This is a function to encode an account number.
Everything works until the routine gets to the spreadsheet function. RANDBETWEEN results in an unknown function error. Using RAND() doesn't give an error, but always results in one(1).
What I'm seeing suggests that my Spreadsheet.Standard.Module1.SetID isn't linked to the spreadsheet functions. I've spent several hours searching. What am I missing?
Thanks
Hertfordkc
NC
_________________
Use it or lose it
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Tue Sep 28, 2010 8:59 pm    Post subject: Reply with quote

Download this:

http://www.pitonyak.org/OOME_3_0.odt

Read section 4.8 on Random Numbers.

Also, here is a hint:

Step 1, at the very top of your module, add "Option Explicit" on a line by itself.

Step 2, replace Rand with Rnd, see if that helps.

I assume that you do not really need to call a Calc function for this, but it is possible, I do it so rarely, however, that I would need to lookup how to do it.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group