Solved

Money currency translated into word for check in VB6 and .NET 2005

Posted on 2010-08-19
24
356 Views
Last Modified: 2012-06-21
We are looking for a solution or a function or routing where we can translate a currency check amount into words.  For example:

$10,953.91  in letters/words, would be:

Ten Thousand Nine Hundred fifty three with 91/100

We looking for English and Spanish...

Whats the best way in doing this?
0
Comment
Question by:rayluvs
  • 14
  • 7
  • 2
  • +1
24 Comments
 
LVL 7

Expert Comment

by:alphaau
ID: 33481691
0
 
LVL 5

Expert Comment

by:ploftin
ID: 33481696
Working on this, but have to call it a night.  Will resume tomorrow.
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33482650
Here is sample in what exactly you want ...
http://www.eggheadcafe.com/fileupload/-1946349607_NamesNumbers.zip
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:rayluvs
ID: 33484175
The sample didn't quite work, for 3,751,258.25, it starts with "billion" when supposed to be thousand and also has no cents.
Numbers.jpg
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33484206
yes you are right ...no cents!!
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33484243
0
 
LVL 5

Expert Comment

by:ploftin
ID: 33484259
Although, it looks like most of the work is done with that sample.  You could take that code and add into it:

1) a "shift" of 3 to the left to remove the decimal and the cents and assign this to a dollars variable.
2) take the left over cents and display it over /100 during the text output.

That's what my code does, but it's not ready yet.  May take another while to complete my code (I'm working a full-time job at the same time), but here's the start of it.  It's not near completion.
MsgBox TranslateCurrency("12.00")

Function TranslateCurrency(myAmount)
	Dim Dollars, Cents
	If InStr(myAmount, ".") Then
		Dollars = Left(myAmount, Len(myAmount)-3)
		Cents = Right(myAmount, 2)
	Else
		Dollars = myAmount
		Cents = 0
	End If
	
	For I = 1 To Len(Dollars)
		NewAmount = DigitToText(Mid(Dollars, I, 1))
	Next
	TranslateCurrency = NewAmount
End Function

Function DigitToText(Digit)
	Select Case Digit
		Case "0"
			DigitToText = "Zero"
		Case "1"
			DigitToText = "One"
		Case "2"
			DigitToText = "Two"
		Case "3"
			DigitToText = "Three"
		Case "4"
			DigitToText = "Four"
		Case "5"
			DigitToText = "Five"
		Case "6"
			DigitToText = "Six"
		Case "7"
			DigitToText = "Seven"
		Case "8"
			DigitToText = "Eight"
		Case "9"
			DigitToText = "Nine"
		Case Else
			DigitToText = -1
		End Select
End Function

Open in new window

0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33484459
try this ...i chekced it
 Dim oneWords As String = ",One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Eleven,Twelve,Thirteen,Fourteen,Fifteen,Sixteen,Seventeen,Eighteen,Nineteen"
    Dim ones() As String = oneWords.Split(",")
    Dim tenWords As String = ",Ten,Twenty,Thirty,Forty,Fifty,Sixty,Seventy,Eighty,Ninety"
    Dim tens() As String = tenWords.Split(",")

    Private Function Convert(ByVal input As String) As String
        input = input.Replace("$", "").Replace(",", "")
        If input.Length > 12 Then Return "Error in input value"
        Dim output, dollars, mills, thous, hunds, cents As String
        Dim mill, thou, hund, cent As Integer
        If input.IndexOf(".") > 0 Then
            dollars = input.Substring(0, input.IndexOf(".")).PadLeft(9, "0")
            cents = input.Substring(input.IndexOf(".") + 1).PadRight(2, "0")
            If cents = "00" Then cents = "0"
        Else
            dollars = input.PadLeft(9, "0") : cents = "0"
        End If
        mill = CType(dollars.Substring(0, 3), Integer) : mills = convertHundreds(mill)
        thou = CType(dollars.Substring(3, 3), Integer) : thous = convertHundreds(thou)
        hund = CType(dollars.Substring(6, 3), Integer) : hunds = convertHundreds(hund)
        cent = CType(cents, Integer) : cents = convertHundreds(cent)
        output = IIf(mills.Trim = "", "", mills + " Million ")
        output += IIf(thous.Trim = "", "", thous + " Thousand ")
        output += IIf(hunds.Trim = "", "", hunds)
        output = IIf(output.Length = 0, "Zero Dollars and ", output + " Dollars and ")
        output = IIf(output = "One Dollars and ", "One Dollar and ", output)
        output += IIf(cents = "", "Zero", cents) + " Cents"
        Return output
    End Function

    Private Function convertHundreds(ByVal input As Integer) As String
        Dim output As String
        If input <= 99 Then
            output = (convertTens(input))
        Else
            output = ones(Floor(input / 100))
            output += " Hundred "
            If input - Floor(input / 100) * 100 = 0 Then
                output += ""
            Else
                output += "" + convertTens(input - Floor(input / 100) * 100)
            End If
        End If
        Return output
    End Function

    Private Function convertTens(ByVal input As Integer) As String
        Dim output As String
        If input < 20 Then
            output = ones(input)
            input = 0
        Else
            output = tens(CType(Floor(input / 10), Integer))
            input -= Floor(input / 10) * 10
        End If
        output = output + IIf(ones(input).Trim = "", "", "-" + ones(input))
        Return output
    End Function
   
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       
        Me.Label1.Text = Convert(Me.TextBox1.Text)
    End Sub

Open in new window

0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33484470
Just copy and paste in form ...
input from Textbox1
output from Label1
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33484490
i forgot the namespace....Sorry
Imports.System.Math
0
 

Author Comment

by:rayluvs
ID: 33484647
Ok.. I paste it and run it and it doesn't work... its giving me Error      Name 'ones' is not declared.

I inserted the texbox and the label, then double click on the form and copy as suggested, am I doing something wrong?
0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 33484687
the code is correct ....put the namespace iittially and after End sub of your form laod event copy it and paste it ...it works
    Dim oneWords As String = ",One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Eleven,Twelve,Thirteen,Fourteen,Fifteen,Sixteen,Seventeen,Eighteen,Nineteen"
    Dim ones() As String = oneWords.Split(",")
    Dim tenWords As String = ",Ten,Twenty,Thirty,Forty,Fifty,Sixty,Seventy,Eighty,Ninety"
    Dim tens() As String = tenWords.Split(",")

    Private Function Convert(ByVal input As String) As String
        input = input.Replace("$", "").Replace(",", "")
        If input.Length > 12 Then Return "Error in input value"
        Dim output, dollars, mills, thous, hunds, cents As String
        Dim mill, thou, hund, cent As Integer
        If input.IndexOf(".") > 0 Then
            dollars = input.Substring(0, input.IndexOf(".")).PadLeft(9, "0")
            cents = input.Substring(input.IndexOf(".") + 1).PadRight(2, "0")
            If cents = "00" Then cents = "0"
        Else
            dollars = input.PadLeft(9, "0") : cents = "0"
        End If
        mill = CType(dollars.Substring(0, 3), Integer) : mills = convertHundreds(mill)
        thou = CType(dollars.Substring(3, 3), Integer) : thous = convertHundreds(thou)
        hund = CType(dollars.Substring(6, 3), Integer) : hunds = convertHundreds(hund)
        cent = CType(cents, Integer) : cents = convertHundreds(cent)
        output = IIf(mills.Trim = "", "", mills + " Million ")
        output += IIf(thous.Trim = "", "", thous + " Thousand ")
        output += IIf(hunds.Trim = "", "", hunds)
        output = IIf(output.Length = 0, "Zero Dollars and ", output + " Dollars and ")
        output = IIf(output = "One Dollars and ", "One Dollar and ", output)
        output += IIf(cents = "", "Zero", cents) + " Cents"
        Return output
    End Function

    Private Function convertHundreds(ByVal input As Integer) As String
        Dim output As String
        If input <= 99 Then
            output = (convertTens(input))
        Else
            output = ones(Floor(input / 100))
            output += " Hundred "
            If input - Floor(input / 100) * 100 = 0 Then
                output += ""
            Else
                output += "" + convertTens(input - Floor(input / 100) * 100)
            End If
        End If
        Return output
    End Function

    Private Function convertTens(ByVal input As Integer) As String
        Dim output As String
        If input < 20 Then
            output = ones(input)
            input = 0
        Else
            output = tens(CType(Floor(input / 10), Integer))
            input -= Floor(input / 10) * 10
        End If
        output = output + IIf(ones(input).Trim = "", "", "-" + ones(input))
        Return output
    End Function

Open in new window

0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33484898
see this
Screen02.JPG
0
 

Author Comment

by:rayluvs
ID: 33484917
Did not quite understand what you mean by iittially, maybe "initially"?, but Thanx for your patience, I'm not pro in .NET, so here it goes:

To be more specific, when I create a new project and double-click on form1, I get:

     Public Class Form1

         Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
               Handles MyBase.Load

         End Sub
     End Class

I place the code (lines 1 thru 58) right after "End sub" and before " End Class"

The namespace, which I assume its Imports.System.Math, where exactly do I place it? before "End sub" ?

Like this:

     Public Class Form1

         Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
               Handles MyBase.Load
          Imports.System.Math
         End Sub
           << code copied here>>
          Imports.System.Math
     End Class

Would this be correct?
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33484939
Imports.System.Math

 Public Class Form1

         Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
               Handles MyBase.Load

         End Sub
  << code copied here>>
     
     End Class
0
 

Author Comment

by:rayluvs
ID: 33485023
Done... I get the following errors:

Error      1      Identifier expected.
            (on line Imports.System.Math)
Error      2      Name 'Floor' is not declared.      
            (on line If input - Floor(input / 100) * 100 = 0 Then)
            (this last error appears 6 times on all "Floor")

FYI: i'm running this in VB 2008 Express Edition

0
 
LVL 18

Assisted Solution

by:John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou earned 500 total points
ID: 33485074
the errors are  due to namespace...
also the floor deppents on math ...LET me ceck it because you are using 2005
0
 

Author Comment

by:rayluvs
ID: 33485083
Ok thanx

FYI: Im using 2008, Visual Basic 2008 Express Edition
0
 

Author Comment

by:rayluvs
ID: 33485180
Ok I found it.... i delete the ".".... its "Imports System.Math"
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33485197
try it now with a button click
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33485504
did you try it?
Because you want it in pounds (English) Replace the Word Dollar with Pounds...Now in spanish You can adjust the code to your own Current Money Words
0
 

Author Comment

by:rayluvs
ID: 33486151
thanx, it worked perfectly
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33486343
Won't You accept a solution?
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33491292
If My Solution Works For You Why Don't You Accept it ?   :)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Gridview selected row 9 47
Disable extension 8 38
Regular expression help 2 25
Help with converting xml file to excel using VB.NET 3 20
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question