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

NumToWords convert 423 to Four Hundred Twenty Three
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
abekz
Newbie
Newbie


Joined: 19 Apr 2007
Posts: 3

PostPosted: Thu Apr 19, 2007 1:33 am    Post subject: Reply with quote

can you created that function in Indonesian Language..??

thanks..
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Fri Apr 20, 2007 11:04 am    Post subject: Reply with quote

You may be the only member in this forum who writes Bahasa Indonesia.
Find some compatriot with programming skills or try it by your own.
Take the spanish or english version and start translating the double-quoted strings "one", "two",... "hundred".
_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
Back to top
View user's profile Send private message
LuisC-SM
General User
General User


Joined: 21 Jun 2007
Posts: 10

PostPosted: Sat Jun 23, 2007 11:32 am    Post subject: Re: Mexican pesos (spanish version) Reply with quote

ryck wrote:
For those who would like the spanish version for ie mexican pesos, here's my NumToPesos Contrib:


ryck:
First off, thanks a lot for your contrib.
I have a couple of questions (or requests) regarding the mexicn version.
As I'm not a coder and don't understand very much this but this is something I really need for my work for my quotations and bank cheques, so my first question is:
This version is a simple macro? or instead 2 of them? 'cause I ran it and gave me the correct values but after the dot is not reading the correct way. reads .... dot three two (instead of thirty two.
I can't make it say instedad of those number mentioned above the correct way which is ##/100 M.N.
Or maybe I'm not executing it the correct way. Either, Ihope youcan enlight my little brain with your comments and remarks.

Kind Regards.

Luis C. Suárez

PS. Probabily I'm not following the correct way to execute the macro

UPDATE (edit)

Ok. I found a my mistake. but there is something wrong with the millions in the macro. I will tell you the two situations with spansih words in numbers
sit 1. $1,200,000.00 Un Millón Doscientos Mil Pesos 00/100 MN
sit 2. $2,200,000.00 Dos Millones Doscientos Mil Pesos 00/100 MN
So the problem is in the situation No. 1 which is always reading "Un Millones instead of Un Millón.
What could possibly be the fix for this?

Thanks a lot and Kind Regards
Back to top
View user's profile Send private message
pkpandya
Newbie
Newbie


Joined: 07 Jul 2007
Posts: 1

PostPosted: Sat Jul 07, 2007 4:27 am    Post subject: how to use this on writer Reply with quote

Hi,

I don't know much of programming. Frankly I don't know what is macro or library. However, I think code on this post may help me. I am using open office writer and love it. I have created an invoice file in writer using table. I want figures (numeric value) of my invoice converted into English words and inserted after the table, where I write E & OE and other information about where to send me payment.

If any one gives me step by step instructions on how to make it work, that will be of great help. Please give reply,
_________________
regards,
Prakash
Back to top
View user's profile Send private message
LuisC-SM
General User
General User


Joined: 21 Jun 2007
Posts: 10

PostPosted: Sat Jul 07, 2007 7:49 am    Post subject: Re: how to use this on writer Reply with quote

pkpandya wrote:
Hi,

I don't know much of programming. Frankly I don't know what is macro or library. However, I think code on this post may help me. I am using open office writer and love it. I have created an invoice file in writer using table. I want figures (numeric value) of my invoice converted into English words and inserted after the table, where I write E & OE and other information about where to send me payment.

If any one gives me step by step instructions on how to make it work, that will be of great help. Please give reply,

A step by step? I don't think that's an easy one for me, instead, I suggestest u go to this place:
http://docs.sun.com/app/docs/doc/819-0439
This is what I did to undestandd a little bit about macros
But the best place to start is by downloading this documment, this will give you a very easy way to understand what u want
http://www.pitonyak.org/AndrewMacro.sxw

I hope this helps

Kind Regards

Luis C. Suárez

PS. Google a little bit in this forums. I've seen some place a step by step way to introduce macros
Back to top
View user's profile Send private message
Nuribat
Newbie
Newbie


Joined: 16 Oct 2008
Posts: 3

PostPosted: Fri Oct 17, 2008 2:28 am    Post subject: Reply with quote

Like Ludo said, I got the same error message when i try to convert number greater than 2147483647.99

I am running OOo 3.00
Anyone can help me?

Thank You
Back to top
View user's profile Send private message
surja
Newbie
Newbie


Joined: 30 Oct 2008
Posts: 4

PostPosted: Thu Oct 30, 2008 8:38 pm    Post subject: number to words for Indian Rupees from existing VBA macro Reply with quote

Hi everyone,
first I must say I'm not a programmer and probably (no, definitely) not bright enough to be one :p. So I hope someone codes this for me and others who may find it useful.
I mostly use Excel if only for the huge number of macros available online and particularly for this one which converts numbers to Indian Rupees.
The most I can do is to paste the VBA code here so someone can take a look and port it to OpenOffice compatible form. I tried to run this code inside OpenOffice but it says something about syntax errors but it runs perfectly in Excel 2003. So here it is:

Code:
Function SpellNumber(ByVal MyNumber, Optional incRupees As Boolean = True)

Dim Crores, Lakhs, Rupees, Paise, Temp

Dim DecimalPlace As Long, Count As Long

Dim myLakhs, myCrores

ReDim Place(9) As String

Place(2) = " Thousand ": Place(3) = " Million "

Place(4) = " Billion ":  Place(5) = " Trillion "

' String representation of amount.

MyNumber = Trim(Str(MyNumber))

' Position of decimal place 0 if none.

DecimalPlace = InStr(MyNumber, ".")

' Convert Paise and set MyNumber to Rupees amount.

If DecimalPlace > 0 Then

Paise = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))

MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))

End If

myCrores = MyNumber \ 10000000

myLakhs = (MyNumber - myCrores * 10000000) \ 100000

MyNumber = MyNumber - myCrores * 10000000 - myLakhs * 100000

Count = 1

Do While myCrores <> ""

Temp = GetHundreds(Right(myCrores, 3))

If Temp <> "" Then Crores = Temp & Place(Count) & Crores

If Len(myCrores) > 3 Then

myCrores = Left(myCrores, Len(myCrores) - 3)

Else

myCrores = ""

End If

Count = Count + 1

Loop

Count = 1

Do While myLakhs <> ""

Temp = GetHundreds(Right(myLakhs, 3))

If Temp <> "" Then Lakhs = Temp & Place(Count) & Lakhs

If Len(myLakhs) > 3 Then

myLakhs = Left(myLakhs, Len(myLakhs) - 3)

Else

myLakhs = ""

End If

Count = Count + 1

Loop

Count = 1

Do While MyNumber <> ""

Temp = GetHundreds(Right(MyNumber, 3))

If Temp <> "" Then Rupees = Temp & Place(Count) & Rupees

If Len(MyNumber) > 3 Then

MyNumber = Left(MyNumber, Len(MyNumber) - 3)

Else

MyNumber = ""

End If

Count = Count + 1

Loop

Select Case Crores

Case "": Crores = ""

Case "One": Crores = " One Crore "

Case Else: Crores = Crores & " Crores "

End Select

Select Case Lakhs

Case "": Lakhs = ""

Case "One": Lakhs = " One Lakh "

Case Else: Lakhs = Lakhs & " Lakhs "

End Select

Select Case Rupees

Case "": Rupees = "Zero "

Case "One": Rupees = "One "

Case Else: Rupees = Rupees

End Select

Select Case Paise

Case "": Paise = " and Paise Zero Only "

Case "One": Paise = " and Paise One Only "

Case Else: Paise = " and Paise " & Paise & " Only "

End Select

SpellNumber = IIf(incRupees, "(Rupees ", "") & Crores & Lakhs & Rupees & Paise & ")"

End Function

' Converts a number from 100-999 into text

Function GetHundreds(ByVal MyNumber)

Dim Result As String

If Val(MyNumber) = 0 Then Exit Function

MyNumber = Right("000" & MyNumber, 3)

' Convert the hundreds place.

If Mid(MyNumber, 1, 1) <> "0" Then

Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "

End If

' Convert the tens and ones place.

If Mid(MyNumber, 2, 1) <> "0" Then

Result = Result & GetTens(Mid(MyNumber, 2))

Else

Result = Result & GetDigit(Mid(MyNumber, 3))

End If

GetHundreds = Result

End Function

' Converts a number from 10 to 99 into text.

Function GetTens(TensText)

Dim Result As String

Result = "" ' Null out the temporary function value.

If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...

Select Case Val(TensText)

Case 10: Result = "Ten"

Case 11: Result = "Eleven"

Case 12: Result = "Twelve"

Case 13: Result = "Thirteen"

Case 14: Result = "Fourteen"

Case 15: Result = "Fifteen"

Case 16: Result = "Sixteen"

Case 17: Result = "Seventeen"

Case 18: Result = "Eighteen"

Case 19: Result = "Nineteen"

Case Else

End Select

Else ' If value between 20-99...

Select Case Val(Left(TensText, 1))

Case 2: Result = "Twenty "

Case 3: Result = "Thirty "

Case 4: Result = "Forty "

Case 5: Result = "Fifty "

Case 6: Result = "Sixty "

Case 7: Result = "Seventy "

Case 8: Result = "Eighty "

Case 9: Result = "Ninety "

Case Else

End Select

Result = Result & GetDigit(Right(TensText, 1))  ' Retrieve ones place.

End If

GetTens = Result

End Function

' Converts a number from 1 to 9 into text.

Function GetDigit(Digit)

Select Case Val(Digit)

Case 1: GetDigit = "One"

Case 2: GetDigit = "Two"

Case 3: GetDigit = "Three"

Case 4: GetDigit = "Four"

Case 5: GetDigit = "Five"

Case 6: GetDigit = "Six"

Case 7: GetDigit = "Seven"

Case 8: GetDigit = "Eight"

Case 9: GetDigit = "Nine"

Case Else: GetDigit = ""

End Select

End Function


Take care and cheers. Smile Cool
Back to top
View user's profile Send private message
bobban
OOo Enthusiast
OOo Enthusiast


Joined: 02 Jan 2008
Posts: 172
Location: Australia

PostPosted: Thu Oct 30, 2008 10:12 pm    Post subject: Reply with quote

surja, post more information. Give some examples of input data you would give that function, and what you would expect the output to be.

And why not use an 'Indian' version of DannyB's original macro in this thread? Is there something missing from that? It will probably be easier to just modify that, than translate the VB code to OO Basic.

I will be happy to have a look at it if you make things easy for me... Smile
_________________
nil sine labore
Back to top
View user's profile Send private message
bobban
OOo Enthusiast
OOo Enthusiast


Joined: 02 Jan 2008
Posts: 172
Location: Australia

PostPosted: Thu Oct 30, 2008 11:03 pm    Post subject: Reply with quote

Surja, see if this works for you.

I tested it using: 32651424.48
and the result is: "(Rupees Three Crores Twenty Six Lakhs Fifty One Thousand Four Hundred Twenty Four and Paise Forty Eight Only )"

Not really sure how Indian currency works personally, so let me know if that's ok.

Code:
Sub Main
   MsgBox(SpellNumber( 32651424.48 ))
End Sub


Function SpellNumber(ByVal MyNumber, Optional incRupees As Boolean)

   Dim Crores, Lakhs, Rupees, Paise, Temp
   Dim DecimalPlace As Long, Count As Long
   Dim myLakhs, myCrores
   ReDim Place(9) As String
   
   if IsMissing(incRupees) then
      incRupees = True
   end if
   
   Place(2) = " Thousand ": Place(3) = " Million "
   Place(4) = " Billion ":  Place(5) = " Trillion "
   
   ' String representation of amount.   
   MyNumber = Trim(Str(MyNumber))
   
   ' Position of decimal place 0 if none.   
   DecimalPlace = InStr(MyNumber, ".")
   
   ' Convert Paise and set MyNumber to Rupees amount.   
   If DecimalPlace > 0 Then
      Paise = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))   
      MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
   End If
   
   MyNumber = Val(MyNumber)
   myCrores = MyNumber \ 10000000
   myLakhs = (MyNumber - myCrores * 10000000) \ 100000
   MyNumber = MyNumber - myCrores * 10000000 - myLakhs * 100000
   
   Count = 1
   Do While myCrores <> ""
      Temp = GetHundreds(Right(myCrores, 3))
      If Temp <> "" Then
         Crores = Temp & Place(Count) & Crores
      End If
            
      If Len(myCrores) > 3 Then
         myCrores = Left(myCrores, Len(myCrores) - 3)
      Else
         myCrores = ""
      End If
      
      Count = Count + 1
   Loop
   
   Count = 1   
   Do While myLakhs <> ""
      Temp = GetHundreds(Right(myLakhs, 3))
      If Temp <> "" Then
         Lakhs = Temp & Place(Count) & Lakhs
      End If
      
      If Len(myLakhs) > 3 Then
         myLakhs = Left(myLakhs, Len(myLakhs) - 3)
      Else
         myLakhs = ""
      End If
      
      Count = Count + 1
   Loop
      
   Count = 1
   Do While MyNumber <> ""
      Temp = GetHundreds(Right(MyNumber, 3))
      If Temp <> "" Then
         Rupees = Temp & Place(Count) & Rupees
      End If

      If Len(MyNumber) > 3 Then      
         MyNumber = Left(MyNumber, Len(MyNumber) - 3)      
      Else      
         MyNumber = ""
      End If
   
      Count = Count + 1
   Loop
   
   Select Case Crores   
      Case "": Crores = ""      
      Case "One": Crores = " One Crore "      
      Case Else: Crores = Crores & " Crores "   
   End Select
   
   Select Case Lakhs
      Case "": Lakhs = ""
      Case "One": Lakhs = " One Lakh "
      Case Else: Lakhs = Lakhs & " Lakhs "
   End Select
   
   Select Case Rupees
      Case "": Rupees = "Zero "
      Case "One": Rupees = "One "
      Case Else: Rupees = Rupees
   End Select
   
   Select Case Paise
      Case "": Paise = " and Paise Zero Only "
      Case "One": Paise = " and Paise One Only "
      Case Else: Paise = " and Paise " & Paise & " Only "
   End Select
   
   SpellNumber = IIf(incRupees, "(Rupees ", "") & Crores & Lakhs & Rupees & Paise & ")"

End Function




' Converts a number from 100-999 into text
Function GetHundreds(ByVal MyNumber)

   Dim Result As String
   
   If Val(MyNumber) = 0 Then Exit Function
   
   MyNumber = Right("000" & MyNumber, 3)
   
   ' Convert the hundreds place.
   If Mid(MyNumber, 1, 1) <> "0" Then
      Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
   End If
   
   ' Convert the tens and ones place.
   If Mid(MyNumber, 2, 1) <> "0" Then
      Result = Result & GetTens(Mid(MyNumber, 2))
   Else
      Result = Result & GetDigit(Mid(MyNumber, 3))
   End If
   
   GetHundreds = Result

End Function



' Converts a number from 10 to 99 into text.
Function GetTens(TensText)

   Dim Result As String
   
   Result = "" ' Null out the temporary function value.
   
   If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
   
      Select Case Val(TensText)
         Case 10: Result = "Ten"
         Case 11: Result = "Eleven"
         Case 12: Result = "Twelve"
         Case 13: Result = "Thirteen"
         Case 14: Result = "Fourteen"
         Case 15: Result = "Fifteen"
         Case 16: Result = "Sixteen"
         Case 17: Result = "Seventeen"
         Case 18: Result = "Eighteen"
         Case 19: Result = "Nineteen"
         Case Else
      End Select
      
      Else ' If value between 20-99...
         Select Case Val(Left(TensText, 1))
         Case 2: Result = "Twenty "
         Case 3: Result = "Thirty "
         Case 4: Result = "Forty "
         Case 5: Result = "Fifty "
         Case 6: Result = "Sixty "
         Case 7: Result = "Seventy "
         Case 8: Result = "Eighty "
         Case 9: Result = "Ninety "
         Case Else
      End Select
      
      Result = Result & GetDigit(Right(TensText, 1))  ' Retrieve ones place.
   
   End If
   
   GetTens = Result

End Function



' Converts a number from 1 to 9 into text.
Function GetDigit(Digit)

   Select Case Val(Digit)
      Case 1: GetDigit = "One"
      Case 2: GetDigit = "Two"
      Case 3: GetDigit = "Three"
      Case 4: GetDigit = "Four"
      Case 5: GetDigit = "Five"
      Case 6: GetDigit = "Six"
      Case 7: GetDigit = "Seven"
      Case 8: GetDigit = "Eight"
      Case 9: GetDigit = "Nine"
      Case Else: GetDigit = ""
   End Select

End Function


p.s. the conversion from excel to OO Basic was very simple and only required two changes. First time I have done that, so was good to see how similar they are.
1- the 'optional' parameter syntax is slightly different
2- the explicit data type conversion of 'MyNumber' to a value before dividing it by a number (excel must handle this internally) using the line: MyNumber = Val(MyNumber)
_________________
nil sine labore
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Thu Oct 30, 2008 11:24 pm    Post subject: Reply with quote

Why does nobody use the search tool? Crore and Lakh are significant words.
http://www.oooforum.org/forum/viewtopic.phtml?t=40445&highlight=lakh
_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
Back to top
View user's profile Send private message
surja
Newbie
Newbie


Joined: 30 Oct 2008
Posts: 4

PostPosted: Fri Oct 31, 2008 4:51 am    Post subject: It Works! Reply with quote

@bobban:
You saved my life buddy. It works perfectly (Surja bows gratefully). And what a prompt response. Thanks man.

The difference in the US number system is something like this:

1 000 000 000
billion million thousands hundreds tens unit

1 00 000 000
crores lakhs thousands hundreds tens unit

So 1 million = 10 lakhs
and 1 billion = 100 crores.

@villeroy:
I did use the search tool but I suppose not as extensively as I should have, so all apologies there. But then if I did search it correctly, I wouldn't have the good fortune of you scolding me here Smile and I wouldn't have known there was a Villeroy in this universe (utter crap, I know). Just kidding, thanks for the advice really Smile Next time I will try to search as thoroughly as I can.
Back to top
View user's profile Send private message
bobban
OOo Enthusiast
OOo Enthusiast


Joined: 02 Jan 2008
Posts: 172
Location: Australia

PostPosted: Fri Oct 31, 2008 4:57 am    Post subject: Reply with quote

hehehe, glad it worked for you surja. Laughing
_________________
nil sine labore
Back to top
View user's profile Send private message
surja
Newbie
Newbie


Joined: 30 Oct 2008
Posts: 4

PostPosted: Fri Oct 31, 2008 5:23 am    Post subject: a tiny problem with the number to Rupees converter Reply with quote

OK dumb me again.
I need a little help on running this macro a bit more easily.
In MS Excel I assigned the keys Ctrl+3 to run the macro. So on clicking Ctrl+3 at the cell where I wanted the converted number-to-text, a box would pop up and I could select the cell with the number I had to convert to text.
In Calc what I have to do is type "=SpellNumber(cell)" for it to run. I did assign Ctrl+3 to the macro but on clicking Ctrl+3, a box titled "OpenOffice.org Error" pops up saying - "A Scripting Framework error occurred while running the Basic script Standard.Module1.SpellNumber. ----- Message: wrong number of paramters!" (It says paramters instead of parameters :-p)
So, how do I run it with the parameters and while clicking Ctrl+3?
I tried searching for how to run macros while inputting parameters but I didn't really get anywhere, so I had to come back here. Sad
Back to top
View user's profile Send private message
bobban
OOo Enthusiast
OOo Enthusiast


Joined: 02 Jan 2008
Posts: 172
Location: Australia

PostPosted: Fri Oct 31, 2008 5:41 am    Post subject: Reply with quote

This function has no capability to ask for input. It just expects the data as parameters when it is called, so when you just run the macro on it's own, there is no data sent to it, hence the error.
_________________
nil sine labore
Back to top
View user's profile Send private message
surja
Newbie
Newbie


Joined: 30 Oct 2008
Posts: 4

PostPosted: Fri Oct 31, 2008 5:58 am    Post subject: Reply with quote

OK so this part is clear, that the function has no provision to ask for input... but how does it work in Excel, where this same function does ask for input?

Could you rework it to ask for input, if it's not too much work? Come on Macro guru Bobban, I know you can do it!!!!!! LOL. As reward I'll thank you profusely and put in a good word for you to the good Lord above. Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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