Public Function Fn_NumToWord(ByVal NumVal As Integer) As String
Dim NoArr() As Integer = {0, 0, 0, 0, 0, 0, 0, 0, 0}
Dim StrLength, i As Integer
Dim TNo As String
TNo = Trim(Str(NumVal))
StrLength = Len(TNo)
For i = 0 To StrLength - 1
NoArr(i) = Microsoft.VisualBasic.Right(TNo, 1)
TNo = Microsoft.VisualBasic.Left(TNo, StrLength - (i + 1))
Next i
Fn_NumToWord = ConvStr(NoArr)
End Function
Private Function ConvStr(ByVal NoA As Integer()) As String
Dim CrVal, LakVal, ThVal, Hval, LaVal As Integer
Dim CoStr As String
CrVal = (NoA(8) * 10) + NoA(7)
LakVal = (NoA(6) * 10) + NoA(5)
ThVal = (NoA(4) * 10) + NoA(3)
Hval = NoA(2)
LaVal = (NoA(1) * 10) + NoA(0)
CoStr = IndStr(CrVal, 0) & IndStr(LakVal, 1) & IndStr(ThVal, 2) & IndStr(Hval, 3)
Dim LaStr As String = IndStr(LaVal, 4)
If CoStr <> "" And LaStr <> "" Then
ConvStr = CoStr & " and " & LaStr
Else
ConvStr = CoStr & LaStr
End If
End Function
Private Function IndStr(ByVal NoVal As Integer, ByVal OrdNo As Integer) As String
Dim S, K As String
Dim LastStr() As String = {"", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ", "Ten ", "Eleven ", "Tweleve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen ", "Twenty"}
Dim OrdArr() As String = {"Crore ", "Lakh ", "Thousand ", "Hundred ", ""}
Dim Valstr() As String = {"", "", "Twenty ", "Thirty ", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}
If NoVal < 20 Then
S = LastStr(NoVal)
Else
S = Valstr(Int(NoVal / 10)) & LastStr(NoVal Mod 10)
End If
If S <> "" Then IndStr = S & OrdArr(OrdNo)
End Function
Monday, October 26, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment