Page 1 of 1

How to create numerology function?

Posted: Mon Jun 22, 2009 7:56 am
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.

Re: How to create numerology function?

Posted: Mon Jun 22, 2009 11:18 am
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]

Re: How to create numerology function?

Posted: Tue Jun 23, 2009 5:27 am
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).

Re: How to create numerology function?

Posted: Tue Jun 23, 2009 5:51 am
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!

Re: How to create numerology function?

Posted: Mon Jun 29, 2009 2:28 pm
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'

Re: How to create numerology function?

Posted: Tue Jun 30, 2009 6:03 am
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.

Re: How to create numerology function?

Posted: Tue Jun 30, 2009 6:26 am
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.

Re: How to create numerology function?

Posted: Wed Jul 01, 2009 10:16 pm
by Valen Banpaia
Okay, I did I fixed that and it's still telling me the same thing.