Results 1 to 6 of 6

Thread: Need Troubleshooting Help [resolved]

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    492

    Resolved Need Troubleshooting Help [resolved]

    I have an application that changes and $$ amount into a written out ammount. Ex. 250$ = Two Hundred Fifty Dollars. I have the following code that i want to modify, but i have found that it doesnt correctly translate the cents part, can you guys help me out on this one and tell me what is causing this, it doesnt always translate incorrectly only on certain occasions. I only have a text box and a command button so it should be easy to set up.

    Example: 243.42 = Two hundres forty three dollars and forty one cents
    another example: 96.86 = Ninety Six Dollars and Eighty Five cents
    while when you do 6.32 it comes up correctly. What is causing this cause i cant find it.

    Thanks for you help in advance.

    VB Code:
    1. Option Explicit
    2.  
    3. Dim Arr1 As Variant
    4. Dim Arr10 As Variant
    5. Dim Arr100 As Variant
    6.  
    7. Private Sub GetWords(Amt As Currency)
    8. Dim d1 As Long
    9. Dim d10 As Long
    10. Dim d100 As Long
    11. Dim d1000 As Long
    12. Dim d100000 As Long
    13. Dim d1000000 As Long
    14. Dim c1 As Long
    15. Dim c10 As Long
    16. Dim Words As String
    17. Dim Amount As Double
    18. Dim tmpAmt As Double
    19.  
    20.  
    21. '///////////////////////////
    22. ' Dollar Processing
    23. '///////////////////////////
    24.  
    25. Amount = Amt
    26.  
    27. d1000000 = Int(Amount / 1000000): Amount = Amount - (d1000000 * 1000000)
    28. d100000 = Int(Amount / 100000): Amount = Amount - (d100000 * 100000)
    29. d1000 = Int(Amount / 1000): Amount = Amount - (d1000 * 1000)
    30. d100 = Int(Amount / 100): Amount = Amount - CDbl(d100 * 100)
    31. d10 = Int(Amount / 10): Amount = Amount - CDbl(d10 * 10)
    32. d1 = Int(Amount): Amount = Amount - d1
    33.  
    34. '///////////////////////////
    35. ' Cents Processing
    36. '///////////////////////////
    37.  
    38. Amount = Amount * 100
    39. c10 = Int(Amount / 10): Amount = Amount - (c10 * 10)
    40. c1 = Int(Amount): Amount = Amount - c1
    41.  
    42. Words = ""
    43.  
    44. '///////////////////////////
    45. ' Dollars Words Processing
    46. '///////////////////////////
    47.  
    48. If d1000000 > 0 Then
    49.    If d1000000 < 19 Then
    50.        Amount = d1000000
    51.        Words = Words & Arr1(d1000000) & " Million "
    52.     Else
    53.     If d1000000 > 19 Then
    54.        Amount = d1000000
    55.        Words = Words & Arr100(Int(d1000000 / 10)): Amount = (d1000000 Mod 10)
    56.        If Amount > 0 Then Words = Words & " " & Arr1(Amount)
    57.        Words = Words & " Million "
    58.     Else
    59.        If d1000 = 0 Then Words = Words & Arr1(d1000000) & " Million "
    60.     End If
    61. End If
    62. End If
    63. If d100000 > 0 Then
    64.     Words = Words & GetHundreds(Int(d100000 / 10)): Amount = (d100000 Mod 10)
    65.     If (Amount > 0 And d1000 = 0) Then
    66.         Words = Words & Arr1(d100000) & " Hundred Thousand "
    67.     Else
    68.     If d1000 > 0 Then Words = Words & Arr1(d100000) & " Hundred "
    69.    
    70.     End If
    71. End If
    72.  
    73. If d1000 > 19 Then
    74.    Amount = d1000
    75.    Words = Words & Arr100(Int(d1000 / 10)): Amount = (d1000 Mod 10)
    76.    If Amount > 0 Then Words = Words & " " & Arr1(Amount)
    77.    Words = Words & " Thousand "
    78. Else
    79.    If d1000 > 0 Then Words = Words & Arr1(d1000) & " Thousand "
    80. End If
    81.  
    82. Words = Words & GetHundreds(d100)
    83. Words = Words & GetTens(d1, d10, " Dollars")
    84.  
    85. '///////////////////////////
    86. ' Cents Words Processing
    87. '///////////////////////////
    88.  
    89. Words = Words & " and " & GetCents(c1, c10, " Cents")
    90. MsgBox Words
    91. Text1.Text = ""
    92.  
    93.  
    94. End Sub
    95. Function GetTens(iones As Long, itens As Long, stype As String) As String
    96. Dim ones, tens As Integer
    97.  
    98. ones = iones
    99. tens = itens
    100.  
    101.     If ones > 0 And tens = 1 Then
    102.        GetTens = GetTens & Arr1(ones + (tens * 10)) & " "
    103.        ones = 0
    104.     Else
    105.        GetTens = GetTens & Arr100(tens) & " "
    106.     End If
    107.    
    108.     If ones > 0 Then
    109.        GetTens = GetTens & Arr1(ones) & stype
    110.     Else
    111.        GetTens = stype
    112.     End If
    113.  
    114. End Function
    115. Function GetCents(iones As Long, itens As Long, stype As String) As String
    116. Dim ones, tens As Integer
    117.  
    118. ones = iones
    119. tens = itens
    120.  
    121.     If ones > 0 And tens = 1 Then
    122.        GetCents = GetCents & Arr1(ones + (tens * 10)) & " "
    123.        ones = 0
    124.     Else
    125.        GetCents = GetCents & Arr100(tens) & " "
    126.     End If
    127.    
    128.     If ones > 0 Then
    129.        GetCents = GetCents & Arr1(ones) & stype
    130.     Else
    131.        GetCents = "Zero" & stype
    132.     End If
    133.  
    134. End Function
    135.  
    136. Function GetHundreds(iHundreds As Long) As String
    137.     If iHundreds > 0 Then GetHundreds = Arr1(iHundreds) & " Hundred "
    138. End Function
    139. Function GetHundredsThs(iHundreds As Long) As String
    140.     If iHundreds > 0 Then GetHundredsThs = Arr1(iHundreds) & " Hundred "
    141. End Function
    142.  
    143. Private Sub Command1_Click()
    144.    GetWords CCur(Val(Text1.Text))
    145. End Sub
    146.  
    147. Private Sub Form_Load()
    148.  
    149. Arr1 = Array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", _
    150.               "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", _
    151.               "Seventeen", "Eighteen", "Ninteen")
    152. Arr10 = Array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine")
    153. Arr100 = Array("", "Ten", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety")
    154.  
    155. End Sub
    Last edited by mrstuff68; Oct 10th, 2005 at 11:39 AM.

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