Results 1 to 5 of 5

Thread: text numbers

  1. #1

    Thread Starter
    Junior Member GhostRider's Avatar
    Join Date
    Oct 2002
    Location
    México
    Posts
    29

    Question text numbers

    is there a way to change numbers to text strings?

    Let me explain:

    I have an application that shows an invoice in a Crystal Report

    I have so far the total as, for example: $ 1526.73

    is there a way to get this value on the fly and create a variable that shows the text?

    such as: (one thousand five hundred and twenty six 73/100)

    Thanx .
    ... on a steel horse I ride, I'm wanted dead or... Dead!...

  2. #2

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    This should do the job too:
    VB Code:
    1. Option Explicit
    2.  
    3. Public Function ToWords(ByVal nAmount As Currency) As String
    4.  
    5.   Dim vSingle As Variant
    6.   Dim vTen As Variant
    7.   Dim sWords As String
    8.   Dim nNew As Currency
    9.  
    10.   vSingle = Split("One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Eleven,Twelve,Thirteen,Fourteen,Fifteen,Sixteen,Seventeen,Eighteen,Nineteen", ",")
    11.   vTen = Split("Ten,Twenty,Thirty,Fourty,Fifty,Sixty,Seventy,Eighty,Ninety", ",")
    12.  
    13.   Do While (nAmount > 0)
    14.     If nAmount > 1000000 Then
    15.       nNew = Int(nAmount / 1000000)
    16.       sWords = sWords & ToWords(nNew) & "MILLION, "
    17.       nAmount = nAmount - (Int(nAmount / 1000000) * 1000000)
    18.     ElseIf nAmount > 1000 Then
    19.       nNew = Int(nAmount / 1000)
    20.       sWords = sWords & ToWords(nNew) & "THOUSAND, "
    21.       nAmount = nAmount - (Int(nAmount / 1000) * 1000)
    22.     ElseIf nAmount > 100 Then
    23.       nNew = Int(nAmount / 100)
    24.       sWords = sWords & ToWords(nNew) & "HUNDRED AND "
    25.       nAmount = nAmount - (Int(nAmount / 100) * 100)
    26.     ElseIf nAmount > 10 Then
    27.       nNew = Int(nAmount / 10)
    28.       If nNew > 1 Then
    29.         sWords = sWords & vTen(nNew - 1) & " "
    30.       Else
    31.         sWords = sWords & vSingle(nAmount - 1) & " "
    32.         nAmount = 0
    33.       End If
    34.       nAmount = nAmount - (Int(nAmount / 10) * 10)
    35.     ElseIf nAmount > 0 Then
    36.       sWords = sWords & vSingle(nAmount - 1) & " "
    37.       nAmount = 0
    38.     End If
    39.   Loop
    40.   If Right(sWords, 2) = ", " Then
    41.     sWords = Left(sWords, Len(sWords) - 2)
    42.   ElseIf Right(sWords, 5) = " AND " Then
    43.     sWords = Left(sWords, Len(sWords) - 5)
    44.   End If
    45.   ToWords = UCase(sWords)
    46.  
    47. End Function

  4. #4
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Try this...
    Attached Files Attached Files
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  5. #5

    Thread Starter
    Junior Member GhostRider's Avatar
    Join Date
    Oct 2002
    Location
    México
    Posts
    29
    thnx guys I'll probe and tell ya
    ... on a steel horse I ride, I'm wanted dead or... Dead!...

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