Results 1 to 14 of 14

Amendments in Function Convert digits to words

Threaded View

  1. #1
    Forum Contributor
    Join Date
    07-21-2009
    Location
    Kuwait
    MS-Off Ver
    Excel 2019
    Posts
    292

    Thumbs up Amendments in Function Convert digits to words

    Hello dears,

    Before I got this Function from your Form to convert digit to words.

    Function is as following..right now i m getting as following:-

    If i type 123..i m getting one Hundred twenty Three with this script as below.

    But i want US Dollar one Hundred Twenty Three..

    Can any one add the word "US Dollar" in this script.

    Script..

    PHP Code: 
    Function English(ByVal N As Currency) As String
                
    Const Thousand 1000@
                Const 
    Million Thousand Thousand
                
    Const Billion Thousand Million
                
    Const Trillion Thousand Billion
                
    If (0@) Then English "zero": Exit Function
                
    Dim Buf As String: If (0@) Then Buf "negative " Else Buf ""
                
    Dim Frac As CurrencyFrac Abs(Fix(N))
                If (
    0@ Or Frac <> 0@) Then N Abs(Fix(N))
                
    Dim AtLeastOne As IntegerAtLeastOne >= 1
                
    If (>= TrillionThen
                    Debug
    .Print N
                    Buf 
    Buf EnglishDigitGroup(Int(Trillion)) & " trillion"
                    
    Int(Trillion) * Trillion
                    
    If (>= 1@) Then Buf Buf " "
                
    End If
                If (
    >= BillionThen
                    Debug
    .Print N
                    Buf 
    Buf EnglishDigitGroup(Int(Billion)) & " billion"
                    
    Int(Billion) * Billion
                    
    If (>= 1@) Then Buf Buf " "
                
    End If
                If (
    >= MillionThen
                    Debug
    .Print N
                    Buf 
    Buf EnglishDigitGroup(Million) & " million"
                    
    N Mod Million
                    
    If (>= 1@) Then Buf Buf " "
                
    End If
                If (
    >= ThousandThen
                    Debug
    .Print N
                    Buf 
    Buf EnglishDigitGroup(Thousand) & " thousand"
                    
    N Mod Thousand
                    
    If (>= 1@) Then Buf Buf " "
                
    End If
                If (
    >= 1@) Then
                    Debug
    .Print N
                    Buf 
    Buf EnglishDigitGroup(N)
                
    End If
                If (
    Frac 0@) Then
                    Buf 
    Buf " exactly"
                
    ElseIf (Int(Frac 100@) = Frac 100@) Then
                    
    If AtLeastOne Then Buf Buf " and "
                    
    Buf Buf Format$(Frac 100@, "00") & "/100"
                
    Else
                    If 
    AtLeastOne Then Buf Buf " and "
                    
    Buf Buf Format$(Frac 10000@, "0000") & "/10000"
                
    End If
                
    English Buf
            End 
    Function

            Private Function 
    EnglishDigitGroup(ByVal N As Integer) As String
                
    Const Hundred " hundred"
                
    Const One "one"
                
    Const Two "two"
                
    Const Three "three"
                
    Const Four "four"
                
    Const Five "five"
                
    Const Six "six"
                
    Const Seven "seven"
                
    Const Eight "eight"
                
    Const Nine "nine"
                
    Dim Buf As StringBuf ""
                
    Dim Flag As IntegerFlag False
                Select 
    Case (100)
                    Case 
    0Buf ""Flag False
                    
    Case 1Buf One HundredFlag True
                    
    Case 2Buf Two HundredFlag True
                    
    Case 3Buf Three HundredFlag True
                    
    Case 4Buf Four HundredFlag True
                    
    Case 5Buf Five HundredFlag True
                    
    Case 6Buf Six HundredFlag True
                    
    Case 7Buf Seven HundredFlag True
                    
    Case 8Buf Eight HundredFlag True
                    
    Case 9Buf Nine HundredFlag True
                End Select
                
    If (Flag <> FalseThen N N Mod 100
                
    If (0Then
                    
    If (Flag <> FalseThen Buf Buf " "
                
    Else
                    
    EnglishDigitGroup Buf
                    
    Exit Function
                
    End If
                
    Select Case (10)
                    Case 
    01Flag False
                    
    Case 2Buf Buf "twenty"Flag True
                    
    Case 3Buf Buf "thirty"Flag True
                    
    Case 4Buf Buf "forty"Flag True
                    
    Case 5Buf Buf "fifty"Flag True
                    
    Case 6Buf Buf "sixty"Flag True
                    
    Case 7Buf Buf "seventy"Flag True
                    
    Case 8Buf Buf "eighty"Flag True
                    
    Case 9Buf Buf "ninety"Flag True
                End Select
                
    If (Flag <> FalseThen N N Mod 10
                
    If (0Then
                    
    If (Flag <> FalseThen Buf Buf "-"
                
    Else
                    
    EnglishDigitGroup Buf
                    
    Exit Function
                
    End If
                
    Select Case (N)
                    Case 
    0:
                    Case 
    1Buf Buf One
                    
    Case 2Buf Buf Two
                    
    Case 3Buf Buf Three
                    
    Case 4Buf Buf Four
                    
    Case 5Buf Buf Five
                    
    Case 6Buf Buf Six
                    
    Case 7Buf Buf Seven
                    
    Case 8Buf Buf Eight
                    
    Case 9Buf Buf Nine
                    
    Case 10Buf Buf "ten"
                    
    Case 11Buf Buf "eleven"
                    
    Case 12Buf Buf "twelve"
                    
    Case 13Buf Buf "thirteen"
                    
    Case 14Buf Buf "fourteen"
                    
    Case 15Buf Buf "fifteen"
                    
    Case 16Buf Buf "sixteen"
                    
    Case 17Buf Buf "seventeen"
                    
    Case 18Buf Buf "eighteen"
                    
    Case 19Buf Buf "nineteen"
                
    End Select
                EnglishDigitGroup 
    Buf
            End 
    Function 
    Thanks in advance..
    Last edited by tariqnaz2005; 11-01-2009 at 07:53 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1