Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

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

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
rayluvs
Asked:
rayluvs
  • 14
  • 7
  • 2
  • +1
2 Solutions
 
Alpha AuCommented:
0
 
ploftinCommented:
Working on this, but have to call it a night.  Will resume tomorrow.
0
 
John (Yiannis) ToutountzoglouCommented:
Here is sample in what exactly you want ...
http://www.eggheadcafe.com/fileupload/-1946349607_NamesNumbers.zip
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rayluvsAuthor Commented:
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
 
John (Yiannis) ToutountzoglouCommented:
yes you are right ...no cents!!
0
 
John (Yiannis) ToutountzoglouCommented:
0
 
ploftinCommented:
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
 
John (Yiannis) ToutountzoglouCommented:
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
 
John (Yiannis) ToutountzoglouCommented:
Just copy and paste in form ...
input from Textbox1
output from Label1
0
 
John (Yiannis) ToutountzoglouCommented:
i forgot the namespace....Sorry
Imports.System.Math
0
 
rayluvsAuthor Commented:
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
 
John (Yiannis) ToutountzoglouCommented:
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
 
John (Yiannis) ToutountzoglouCommented:
see this
Screen02.JPG
0
 
rayluvsAuthor Commented:
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
 
John (Yiannis) ToutountzoglouCommented:
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
 
rayluvsAuthor Commented:
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
 
John (Yiannis) ToutountzoglouCommented:
the errors are  due to namespace...
also the floor deppents on math ...LET me ceck it because you are using 2005
0
 
rayluvsAuthor Commented:
Ok thanx

FYI: Im using 2008, Visual Basic 2008 Express Edition
0
 
rayluvsAuthor Commented:
Ok I found it.... i delete the ".".... its "Imports System.Math"
0
 
John (Yiannis) ToutountzoglouCommented:
try it now with a button click
0
 
John (Yiannis) ToutountzoglouCommented:
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
 
rayluvsAuthor Commented:
thanx, it worked perfectly
0
 
John (Yiannis) ToutountzoglouCommented:
Won't You accept a solution?
0
 
John (Yiannis) ToutountzoglouCommented:
If My Solution Works For You Why Don't You Accept it ?   :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 14
  • 7
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now