How to create numerology function?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Valen Banpaia
Posts: 10
Joined: Mon Jun 22, 2009 7:37 am

How to create numerology function?

Post by Valen Banpaia »

Hello, I'm trying to make a numerology funtion to be utilized in Calc. I understand how to make a function and have already made a Fibonacci sequence function, a human-to-cat-years conversion function, and the previous function's inverse. But inorder to make the numerology function I need to know how to convert the letters to their respective numbers and add the digits of the resulting number together. I understand how to create the function when I have a preset phrase, but I'm unsure when the phrase is variable. Help me, please and thank you.
OOo 3.2.1 on MS Windows Vista Home Premium
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to create numerology function?

Post by Villeroy »

In Python:

Code: Select all

LetterMap={'v':13,'o':259.23,'d':987.1234}
n = 0
For c in 'voodoo':
  n += LetterMap[c]
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
Valen Banpaia
Posts: 10
Joined: Mon Jun 22, 2009 7:37 am

Re: How to create numerology function?

Post by Valen Banpaia »

Thanks for the suggestion, but Python macros don't work on mine (whether they don't work on my computer or version of OOo, I do not know).
OOo 3.2.1 on MS Windows Vista Home Premium
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How to create numerology function?

Post by FJCC »

I agree with Villeroy that writing this in Python would be far easier. The Python macros work fine on my OOo 3.1 with XP and the Python is now version 2.6. It might be worth starting another thread to ask why your python macros don't work. In any case, if you post your code for finding the value of a set string, it might be easier to suggest how to change it to accept any input.

Your set of functions for a Fibonacci sequence, cat years and numerology is quite an eclectic set!
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How to create numerology function?

Post by FJCC »

Thanks to Villeroy for doing all the heavy lifting on this. His solution is here. I thought I would post my version in this thread just to have the solution with the original question. Obviously, I used his code from 2007 as a template.
The Basic function I wrote is:

Code: Select all

Function Numer(word)
MSPF = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
scriptPro = MSPF.createScriptProvider("")
xScript = scriptPro.getScript("vnd.sun.star.script:Numerology.py$Main?language=Python&location=user")
Numer = xScript.Invoke(Array(word), Array(), Array())
End function
I modified his python code slightly, since mine insists on the "for" being all lower case and I didn't want to think too hard about the value of "voodoo"

Code: Select all

LetterMap={'v':1,'o':2,'d':3}

def Main(word):

  n = 0
  for c in word:
    n += LetterMap[c] 
  return n
I saved that in a text file named Numerology.py in the folder C:\Documents and Settings\username\Application Data\OpenOffice\3\user\Scripts\python. Using the formula

Code: Select all

=Numer("voodoo")
returns the value 12, as expected. Obviously you will have to expand the dictionary in the python code to include characters other than 'v', 'o', and 'd'
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Valen Banpaia
Posts: 10
Joined: Mon Jun 22, 2009 7:37 am

Re: How to create numerology function?

Post by Valen Banpaia »

Okay, I tried that and said that it was an invalid location. I did, I made sure to, correctly replace the users.
OOo 3.2.1 on MS Windows Vista Home Premium
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How to create numerology function?

Post by FJCC »

You only have to replace the username in the file path with whatever is correct for your system. The "user" farther down the folder name (OpenOffice\3\user\Scripts\python) is the folder name of your profile and needs to remain "user". Sorry I wasn't clear about that.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Valen Banpaia
Posts: 10
Joined: Mon Jun 22, 2009 7:37 am

Re: How to create numerology function?

Post by Valen Banpaia »

Okay, I did I fixed that and it's still telling me the same thing.
OOo 3.2.1 on MS Windows Vista Home Premium
Post Reply