0
Former Member
Dec 04, 2008 at 03:57 AM

# Convert currency to Words(font Vietnamness)

77 Views

Hi all,

I create report as crystal report tool .but I canu2019t convert currency number to vietnamness.

I can only convert to English.

URL=http://imageshack.usIMGhttp://img518.imageshack.us/img518/931/phieuchiqn6.png[/IMG][/url]

I can not convert from number to word u2018s VietNamness.

I used create Customer Function in Crystal report for event this convert.But, it donu2019t work .

I create this function in VB.NET ,it work very good.

This is picture that I used in VB.NET.

Now, I want to add this function into crystal report ,What do me do?

This is code :

Module Module2

Function ConvertCurrencyToEnglish(ByVal MyNumber As String)

Dim Temp

Dim Dollars, Cents As String

Dim DecimalPlace, Count As Integer

Dim Place(9) As String

Place(2) = " Nghìn "

Place(3) = "Triệu "

Place(4) = " Tỉ "

Place(5) = "Trăm tỉ "

' Convert MyNumber to a string, trimming extra spaces.

MyNumber = Trim(MyNumber)

' Find decimal place.

DecimalPlace = InStr(MyNumber, ".")

' If we find decimal place...

If DecimalPlace > 0 Then

' Convert cents

Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)

Cents = ConvertTens(Temp)

' Strip off cents from remainder to convert.

MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))

End If

Count = 1

Do While MyNumber ""

' Convert last 3 digits of MyNumber to English dollars.

Temp = ConvertHundreds(Right(MyNumber, 3))

If Temp "" Then Dollars = Temp & Place(Count) & Dollars

If Len(MyNumber) > 3 Then

' Remove last 3 converted digits from MyNumber.

MyNumber = Left(MyNumber, Len(MyNumber) - 3)

Else

MyNumber = ""

End If

Count = Count + 1

Loop

' Clean up dollars.

Select Case Dollars

Case ""

Dollars = "Không Đồng"

Case "One"

Dollars = "Một Đồng"

Case Else

Dollars = Dollars & " Đồng"

End Select

' Clean up cents.

Select Case Cents

Case ""

Cents = " Chẵn"

Case "One"

Cents = " Lẻ"

Case Else

Cents = " And " & Cents & " Cents"

End Select

ConvertCurrencyToEnglish = Dollars & Cents

End Function

Private Function ConvertHundreds(ByVal MyNumber)

Dim Result As String

' Exit if there is nothing to convert.

If Val(MyNumber) = 0 Then Exit Function

' Append leading zeros to number.

MyNumber = Right("000" & MyNumber, 3)

' Do we have a hundreds place digit to convert?

If Left(MyNumber, 1) "0" Then

Result = ConvertDigit(Left(MyNumber, 1)) & " Chăm "

End If

' Do we have a tens place digit to convert?

If Mid(MyNumber, 2, 1) "0" Then

Result = Result & ConvertTens(Mid(MyNumber, 2))

Else

' If not, then convert the ones place digit.

Result = Result & ConvertDigit(Mid(MyNumber, 3))

End If

ConvertHundreds = Trim(Result)

End Function

Private Function ConvertTens(ByVal MyTens)

Dim Result As String

' Is value between 10 and 19?

If Val(Left(MyTens, 1)) = 1 Then

Select Case Val(MyTens)

Case 10 : Result = "Mười"

Case 11 : Result = "Mười Một"

Case 12 : Result = "Mười Hai"

Case 13 : Result = "Mười Ba"

Case 14 : Result = "Mười Bốn"

Case 15 : Result = "Mười Năm"

Case 16 : Result = "Mười Sáu"

Case 17 : Result = "Mười Bảy"

Case 18 : Result = "Mười Tám"

Case 19 : Result = "Mười Chín"

Case Else

End Select

Else

' .. otherwise it's between 20 and 99.

Select Case Val(Left(MyTens, 1))

Case 2 : Result = "Hai Mươi "

Case 3 : Result = "Ba Mươi "

Case 4 : Result = "Bốn Mươi "

Case 5 : Result = "Năm Mươi "

Case 6 : Result = "Sáu Mươi "

Case 7 : Result = "Bảy Mươi "

Case 8 : Result = "Tám Mươi "

Case 9 : Result = "Chín Mươi "

Case Else

End Select

' Convert ones place digit.

Result = Result & ConvertDigit(Right(MyTens, 1))

End If

ConvertTens = Result

End Function

Private Function ConvertDigit(ByVal MyDigit As Object)

Select Case Val(MyDigit)

Case 1 : ConvertDigit = "Một"

Case 2 : ConvertDigit = "Hai"

Case 3 : ConvertDigit = "Ba"

Case 4 : ConvertDigit = "Bốn"

Case 5 : ConvertDigit = "Năm"

Case 6 : ConvertDigit = "Sáu"

Case 7 : ConvertDigit = "Bảy"

Case 8 : ConvertDigit = "Tám"

Case 9 : ConvertDigit = "Chín"

Case Else : ConvertDigit = ""

End Select

End Function

End Module

Thank you ,