+ Reply to Thread
Results 1 to 5 of 5

Spell number

Hybrid View

nowfal Spell number 08-18-2007, 04:29 PM
mudraker This section determines what... 08-18-2007, 07:09 PM
nowfal Sorry that is not working. 08-19-2007, 05:52 AM
mudraker On your 1st post you said... 08-19-2007, 05:22 PM
nowfal Mr.Mudraker i appreciate your... 08-20-2007, 04:21 PM
  1. #1
    Forum Contributor
    Join Date
    05-27-2004
    Posts
    119

    Spell number

    Hi,
    I have a spellnumber code as follows


      Option Explicit
    Function SpellNumber(ByVal MyNumber, Optional Curr As String = "INR") As String
    Dim Pounds, Pence, Temp
    Dim DecimalPlace, Count
    Dim Curr1, Curr2, Curr3, Curr4 As String
    ReDim Place(9) As String
    If Curr = "INR" Then
    Curr1 = "": Curr2 = " PAISE ONLY": Curr3 = "": Curr4 = "PAISE ONLY"
    End IfIf Curr = "OTH" Then
    Curr1 = "": Curr2 = "  ONLY": Curr3 = "": Curr4 = "ONLY"
    End If
    If Curr = "GBP" Then
    Curr1 = " ": Curr2 = " PENCE ONLY": Curr3 = "": Curr4 = "PENNY ONLY"
    End If
    If Curr = "USD" Then
    Curr1 = " ": Curr2 = " CENTS ONLY": Curr3 = "": Curr4 = "CENT ONLY"
    End If
    If Curr = "BDT" Then
    Curr1 = "": Curr2 = " PAISA ONLY": Curr3 = "": Curr4 = "PAISA ONLY"
    End If
    If Curr = "LKR" Then
    Curr1 = "": Curr2 = "PAISA ONLY": Curr3 = "": Curr4 = "PAISA ONLY"
    End If
    Application.Volatile True
    Place(2) = "THOUSAND "
    Place(3) = "MILLION "
    Place(4) = "BILLION "
    Place(5) = "TRILLION "
    MyNumber = Trim(Str(MyNumber))
    DecimalPlace = InStr(MyNumber, ".")
    If DecimalPlace > 0 Then
    Pence = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
    MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If
    Count = 1
    Do While MyNumber <> ""
    Temp = GetHundreds(Right(MyNumber, 3))
    If Temp <> "" Then Pounds = Temp & Place(Count) & Pounds
    If Len(MyNumber) > 3 Then
    MyNumber = Left(MyNumber, Len(MyNumber) - 3)
    Else
    MyNumber = ""
    End If
    Count = Count + 1
    Loop
    Select Case Pounds
    Case ""
    Pounds = "No " & Curr1
    Case "ONE"
    Pounds = "ONE " & Curr3
    Case Else
    Pounds = Pounds & Curr1
    End Select
    Select Case Pence
    Case ""
    Pence = " ONLY "
    Case "ONE"
    Pence = "  ONE " & Curr4
    Case Else
    Pence = " AND " & Pence & Curr2
    End Select
    SpellNumber = Pounds & Pence
    End Function
    Private Function GetHundreds(ByVal MyNumber)
    Dim Result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
    If Mid(MyNumber, 1, 1) <> "0" Then
    Result = GetDigit(Mid(MyNumber, 1, 1)) & "HUNDRED "
    End If
    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
    Private Function GetTens(TensText)
    Dim Result As String
    Result = ""
    If Val(Left(TensText, 1)) = 1 Then
    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
    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))
    End If
    GetTens = Result
    End Function
    Private 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
    cell A2 is 10.42
    if i put =spellnumber(A2) i am getting the result as TEN AND FORTY TWO PENCE ONLY Instead i wanted TEN AND PENCE FORTY TWO ONLY.
    in the code where do i make the correction? i have highlighted the area with red font may be the area to check. i hope somebody will help.
    thanks and regards
    nowfal

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    This section determines what words are used at the end

       If Curr = "INR" Then
          Curr1 = "": Curr2 = " PAISE ONLY": Curr3 = "": Curr4 = "PAISE ONLY"
       End If
       If Curr = "OTH" Then
          Curr1 = "": Curr2 = "  ONLY": Curr3 = "": Curr4 = "ONLY"
       End If
       If Curr = "GBP" Then
          Curr1 = " ": Curr2 = " PENCE ONLY": Curr3 = "": Curr4 = "PENNY ONLY"
       End If
       If Curr = "USD" Then
          Curr1 = " ": Curr2 = " CENTS ONLY": Curr3 = "": Curr4 = "CENT ONLY"
       End If
       If Curr = "BDT" Then
          Curr1 = "": Curr2 = " PAISA ONLY": Curr3 = "": Curr4 = "PAISA ONLY"
       End If
       If Curr = "LKR" Then
          Curr1 = "": Curr2 = "PAISA ONLY": Curr3 = "": Curr4 = "PAISA ONLY"
       End If

    This section joins the amount with the wording from the above code

       Select Case Pence
       Case ""
          Pence = " ONLY "
       Case "ONE"
          Pence = "  ONE " & Curr4
       Case Else
          Pence = " AND " & Pence & Curr2
       End Select
    Both will need to be modified
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Forum Contributor
    Join Date
    05-27-2004
    Posts
    119
    Sorry that is not working.

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    On your 1st post you said "where do i make the correction"

    I posted a copy of your code showing the areas of code you need to change.

  5. #5
    Forum Contributor
    Join Date
    05-27-2004
    Posts
    119
    Mr.Mudraker i appreciate your reply. After doing your suggestion the result is negative so, i thought i can continue with the present form.
    anyway thanks for your help.
    with regards
    NOWFAL

+ Reply to Thread

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