Вы находитесь на странице: 1из 5

The given code can explain to convert the number to word in crystal report

1) right click on your formula field


2) click edit formula
3) formula workshop window will open
4) left side of the window u have 'report custom functions'
5)right click and select new
6)give the name for function
7) and the right top you have a drop down. it shows 'Crystal Syntax' as default
8)change this to basic syntax.
9) save the function.
do the above steps for the following functions also

--------------------------------------------------------------------------------
---------------
A L L F U N C T I O N S S T A R T S
--------------------------------------------------------------------------------
---------------
Function ConvertDigit(MyDigit as string)
if Val(MyDigit) = 1 then
ConvertDigit = "One"
elseif Val(MyDigit) = 2 then
ConvertDigit = "Two "
elseif Val(MyDigit) = 3 then
ConvertDigit = "Three "
elseif Val(MyDigit) = 4 then
ConvertDigit = "Four "
elseif Val(MyDigit) = 5 then
ConvertDigit = "Five "
elseif Val(MyDigit) = 6 then
ConvertDigit = "Six "
elseif Val(MyDigit) = 7 then
ConvertDigit = "Seven "
elseif Val(MyDigit) = 8 then
ConvertDigit = "Eight "
elseif Val(MyDigit) = 9 then
ConvertDigit = "Nine "
end if
End Function
================================================================================
===============
Function ConvertHundreds(MyNumber as string)
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)) & " Hundreds "
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
================================================================================
===============
Function ConvertTens(MyTens as string)
Dim Result As String
' Is value between 10 and 19?
If Val(Left(MyTens, 1)) = 1 Then
if Val(MyTens) = 10 then
Result = "Ten"
elseif Val(MyTens) = 11 then
Result = "Eleven"
elseif Val(MyTens) = 12 then
Result = "Twelve"
elseif Val(MyTens) = 13 then
Result = "Thirteen"
elseif Val(MyTens) = 14 then
Result = "Fourteen"
elseif Val(MyTens) = 15 then
Result = "Fifteen"
elseif Val(MyTens) = 16 then
Result = "Sixteen"
elseif Val(MyTens) = 17 then
Result = "Seventeen"
elseif Val(MyTens) = 18 then
Result = "Eighteen"
elseif Val(MyTens) = 19 then
Result = "Nineteen"
end if
Else
if Val(Left(MyTens, 1)) = 2 then
Result = "Twenty "
elseif Val(Left(MyTens, 1)) = 3 then
Result = "Thirty "
elseif Val(Left(MyTens, 1)) = 4 then
Result = "Forty "
elseif Val(Left(MyTens, 1)) = 5 then
Result = "Fifty "
elseif Val(Left(MyTens, 1)) = 6 then
Result = "Sixty "
elseif Val(Left(MyTens, 1)) = 7 then
Result = "Seventy "
elseif Val(Left(MyTens, 1)) = 8 then
Result = "Eighty "
elseif Val(Left(MyTens, 1)) = 9 then
Result = "Ninety "
end if
Result = Result & ConvertDigit(Right(cstr(MyTens), 1))
end if
' Convert ones place digit.
ConvertTens = Result
End Function
================================================================================
===============
Function RupeesToWord(MyNumber As string)
Dim Temp
Dim Rupees, Paisa As String
Dim DecimalPlace, iCount
Dim Hundreds, Words As String
'Dim place(9) As String
'place[0] = " Thousand "
'place(2) = " Lakh "
'place(4) = " Crore "
'place(6) = " Arab "
'place(8) = " Kharab "
'Dim place(9) As String
'place(0) = " Thousand "
'place(2) = " Lakh "
'place(4) = " Crore "
'place(6) = " Arab "
'place(8) = " Kharab "
' On Error Resume Next
' Convert MyNumber to a string, trimming extra spaces.
MyNumber = Trim(CStr(MyNumber))
' Find decimal place.
DecimalPlace = InStr(MyNumber, ".")
' If we find decimal place...
If DecimalPlace > 0 Then
' Convert Paisa
Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
Paisa = " and " & ConvertTens(Temp) & " Paisa"
' Strip off paisa from remainder to convert.
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
if Paisa= " and Paisa" then Paisa=""
end if
End If
'===============================================================
Dim TM As String ' If MyNumber between Rs.1 To 99 Only.
TM = Right(MyNumber, 2)
If Len(MyNumber) > 0 And Len(MyNumber) <= 2 Then
If Len(TM) = 1 Then
Words = ConvertDigit(TM)
if Paisa= " and Paisa" then
Paisa=""
end if
RupeesToWord = "Rupees " & Words & Paisa & " Only"
Exit Function
Else
If Len(TM) = 2 Then
Words = ConvertTens(TM)
if Paisa= " and Paisa" then Paisa=""
end if
RupeesToWord = "Rupees " & Words & Paisa & " Only"
Exit Function
End If
End If
End If
'===============================================================
' Convert last 3 digits of MyNumber to ruppees in word.
Hundreds = ConvertHundreds(Right(MyNumber, 3))
' Strip off last three digits
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
iCount = 0
Do While MyNumber <> ""
'Strip last two digits
Temp = Right(MyNumber, 2)
dim str1 as string
if iCount = 0 then
str1 =" Thousand "
elseif iCount = 2 then
str1 =" Lakh "
elseif iCount =4 then
str1 =" Crore "
elseif iCount =6 then
str1 =" Arab "
elseif iCount =8 then
str1 =" Kharab "
end if
If Len(MyNumber) = 1 Then
If Trim(Words) = "Thousand" Or _
Trim(Words) = "Lakh Thousand" Or _
Trim(Words) = "Lakh" Or _
Trim(Words) = "Crore" Or _
Trim(Words) = "Crore Lakh Thousand" Or _
Trim(Words) = "Arab Crore Lakh Thousand" Or _
Trim(Words) = "Arab" Or _
Trim(Words) = "Kharab Arab Crore Lakh Thousand" Or _
Trim(Words) = "Kharab" Then
'place(0) = " Thousand "
'place(2) = " Lakh "
'place(4) = " Crore "
'place(6) = " Arab "
'place(8) = " Kharab "
Words = ConvertDigit(Temp) & str1
MyNumber = Left(MyNumber, Len(MyNumber) - 1)
Else
Words = ConvertDigit(Temp) & str1 & Words
MyNumber = Left(MyNumber, Len(MyNumber) - 1)
End If
Else
If Trim(Words) = "Thousand" Or _
Trim(Words) = "Lakh Thousand" Or _
Trim(Words) = "Lakh" Or _
Trim(Words) = "Crore" Or _
Trim(Words) = "Crore Lakh Thousand" Or _
Trim(Words) = "Arab Crore Lakh Thousand" Or _
Trim(Words) = "Arab" Then
Words = ConvertTens(Temp) & str1
MyNumber = Left(MyNumber, Len(MyNumber) - 2)
Else
'===========================================================
======
' if only Lakh, Crore, Arab, Kharab
If Trim(ConvertTens(Temp) & str1) = "Lakh" Or _
Trim(ConvertTens(Temp) & str1) = "Crore" Or _
Trim(ConvertTens(Temp) & str1) = "Arab" Then
Words = Words
MyNumber = Left(MyNumber, Len(MyNumber) - 2)
Else
Words = ConvertTens(Temp) & str1 & Words
MyNumber = Left(MyNumber, Len(MyNumber) - 2)
End If
End If
End If
iCount = iCount + 2
Loop
if Paisa= " and Paisa" then
Paisa=""
end if
RupeesToWord = "Rupees " & Words & Hundreds & Paisa & " Only"
end Function
--------------------------------------------------------------------------------
---------------
E N D O F A L L F U N C T I O N S
--------------------------------------------------------------------------------
---------------
pass ur number to RupeesToword function