[Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register]

Author Message
hertfordkc
Newbie

Joined: 24 Oct 2006
Posts: 1
Location: NC

 Posted: Sun Sep 19, 2010 5:16 pm    Post subject: Use of Calc functions within a Basic Macro 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
pitonyak

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

 Posted: Tue Sep 28, 2010 8:59 pm    Post subject: 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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT - 8 Hours Page 1 of 1

 Jump to: Select a forum OpenOffice.org Forums----------------Setup and TroubleshootingOpenOffice.org WriterOpenOffice.org CalcOpenOffice.org ImpressOpenOffice.org DrawOpenOffice.org MathOpenOffice.org BaseOpenOffice.org Macros and APIOpenOffice.org Code Snippets Community Forums----------------General DiscussionSite Feedback
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