CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2010
    Posts
    7

    Numbers to Words

    hey

    I have excel userform which I can make Invoice.

    When I Calculate, I need the total amount to be Words.
    Whole amount is converted to words except the decimal.

    I need the decimal also to be in words.

    Please Help me.

    Regards
    Kid
    Attached Files Attached Files

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Numbers to Words

    It seems, all the tools are already present in your worksheet.
    The function SpellNumber() in module amntWords seems to do exactly what you require, provided you have "." as a decimal separator.

    Only that some mischieveous mind has commented out a valuable statement.
    Look into the module amntWords.
    Examine the
    Function SpellNumber(ByVal MyNumber)
    The very last line before End Function is
    SpellNumber = SAR '& Cents
    somebody has commented out the & Cents. It must be:
    SpellNumber = SAR & Cents

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Numbers to Words

    That would be the teacher, I'd bet...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    May 2010
    Posts
    7

    Re: Numbers to Words

    Hello Sir,

    After alteration as per your advise, Still my file doesn't shows decimal in words.

    Is it working on your PC? If it is working, Is there any settings I need to change in my
    computer?

    Could you please help me.

    Regards
    Kid

  5. #5
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Numbers to Words

    @David: Possibly.

    It works on my computer.
    I just go to some empty cell and enter =spellnumber(123.45) and press enter.
    The cell would then show One Hundred Twenty ThreeForty Five

    Come to look at it, we would have to insert the word "Point" at where the decimal point is.
    We'd modify the statement where the Cents variable is loaded:
    Code:
        If DecimalPlace > 0 Then
            Cents = "Point " & GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
                      "00", 2))
    It would then say One Hundred Twenty Three Point Forty Five

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Numbers to Words

    and 45/100 (or else 00/100)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Numbers to Words

    Two-Thousand Four-Hundred Ninety-Five and 45/100 (or else 00/100)
    This is how checks should be written
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Numbers to Words

    Quote Originally Posted by WoF View Post

    We'd modify the statement where the Cents variable is loaded:
    Code:
        If DecimalPlace > 0 Then
            Cents = "Point " & GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
                      "00", 2))
    It would then say One Hundred Twenty Three Point Forty Five
    Curious as to why you used Left() in the code above?

    Code:
     
    If DecimalPlace > 0 Then
            Cents = "Point " & GetTens(Mid(MyNumber & "00", DecimalPlace + 1,2)
    Would do the same thing without the additional function call.
    Always use [code][/code] tags when posting code.

  9. #9
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Numbers to Words

    That's right. Well spotted. That line of code has been part of the original code. I didn't notice.
    Surely a Mid$() is all you need there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured