VERSION 5.00
Begin VB.Form frmMain
Caption = "Main"
ClientHeight = 3360
ClientLeft = 3015
ClientTop = 1125
ClientWidth = 5940
LinkTopic = "Form1"
ScaleHeight = 3360
ScaleWidth = 5940
Begin VB.TextBox txtWords
Height = 525
Left = 120
MultiLine = -1 'True
TabIndex = 2
Top = 2760
Width = 5655
End
Begin VB.CommandButton cmdConvert
Caption = "Convert"
Height = 855
Left = 1680
TabIndex = 1
Top = 1200
Width = 2535
End
Begin VB.TextBox txtDigit
Height = 405
Left = 1680
TabIndex = 0
Top = 240
Width = 2535
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim noLen As Byte
Dim arrOneToNinety(27) As String
Public Function lenOne(strTemp As String) As String
'While Left(txtDigit.Text, 1) = 0
' txtDigit.Text = Right(txtDigit.Text, Len(txtDigit.Text) - 1)
'Wend
lenOne = arrOneToNinety(CInt(strTemp))
End Function
Public Function lenTwo(strTemp As String)
Dim strTemp1, strTemp2 As String
If (CInt(strTemp)) <= 20 Then
If (CInt(strTemp)) = 18 Then
strTemp2 = "Eighteen"
Else
strTemp2 = arrOneToNinety(CInt(strTemp))
End If
Else
strTemp1 = arrOneToNinety(CInt(Mid(strTemp, 1, 1)) + 18)
strTemp2 = strTemp1 & " " & lenOne(Mid(strTemp, 2, 1))
End If
lenTwo = strTemp2
End Function
Public Function lenThree(strTemp As String)
Dim strTemp1, strTemp2 As String
strTemp1 = lenOne(Mid(strTemp, 1, 1))
If (Len(strTemp1) <> 0) Then
strTemp1 = strTemp1 & " " & "Hundred"
End If
strTemp2 = lenTwo(Mid(strTemp, 2, 2))
lenThree = strTemp1 & " " & strTemp2
End Function
Public Function lenFour(strTemp As String)
Dim strTemp1, strTemp2 As String
strTemp1 = lenOne(Mid(strTemp, 1, 1))
If (Len(strTemp1) <> 0) Then
strTemp1 = strTemp1 & " " & "Thousand"
End If
strTemp2 = lenThree(Mid(strTemp, 2, 3))
lenFour = strTemp1 & " " & strTemp2
End Function
Public Function lenFive(strTemp As String)
Dim strTemp1, strTemp2 As String
strTemp1 = lenTwo(Mid(strTemp, 1, 2))
If (Len(strTemp1) <> 0) Then
strTemp1 = strTemp1 & " " & "Thousand"
End If
strTemp2 = lenThree(Mid(strTemp, 3, 3))
lenFive = strTemp1 & " " & strTemp2
End Function
Public Function lenSix(strTemp As String)
Dim strTemp1, strTemp2 As String
strTemp1 = lenTwo(Mid(strTemp, 1, 1))
If (Len(strTemp1) <> 0) Then
strTemp1 = strTemp1 & " " & "Lakhs"
End If
strTemp2 = lenFive(Mid(strTemp, 2, 5))
lenSix = strTemp1 & " " & strTemp2
End Function
Public Function lenSeven(strTemp As String)
Dim strTemp1, strTemp2 As String
strTemp1 = lenTwo(Mid(strTemp, 1, 2))
If (Len(strTemp1) <> 0) Then
strTemp1 = strTemp1 & " " & "Lakhs"
End If
strTemp2 = lenFive(Mid(strTemp, 3, 5))
lenSeven = strTemp1 & " " & strTemp2
End Function
Public Function lenEight(strTemp As String)
Dim strTemp1, strTemp2 As String
strTemp1 = lenOne(Mid(strTemp, 1, 1))
If (Len(strTemp1) <> 0) Then
strTemp1 = strTemp1 & " " & "Crores"
End If
strTemp2 = lenSeven(Mid(strTemp, 2, 7))
lenEight = strTemp1 & " " & strTemp2
End Function
Public Function printToWords(strTemp As String)
Select Case Len(strTemp)
Case 1
txtWords.Text = txtWords.Text & lenOne(strTemp)
Case 2
If (CInt(strTemp)) <= 20 Then
If (CInt(strTemp)) = 18 Then
txtWords.Text = txtWords.Text & "Eighteen"
Else
txtWords.Text = txtWords.Text & arrOneToNinety(CInt(txtDigit.Text))
End If
Else
txtWords.Text = txtWords.Text & lenTwo(strTemp)
End If
Case 3
txtWords.Text = txtWords.Text & lenThree(strTemp)
Case 4
txtWords.Text = txtWords.Text & lenFour(strTemp)
Case 5
txtWords.Text = txtWords.Text & lenFive(strTemp)
Case 6
txtWords.Text = txtWords.Text & lenSix(strTemp)
Case 7
txtWords.Text = txtWords.Text & lenSeven(strTemp)
Case 8
txtWords.Text = txtWords.Text & lenEight(strTemp)
End Select
End Function
Private Sub cmdConvert_Click()
Dim strWhole, strDecimal As String
txtWords.Text = ""
'While Left(txtDigit.Text, 1) = 0
' txtDigit.Text = Right(txtDigit.Text, Len(txtDigit.Text) - 1)
'Wend
strWhole = printToWords(Mid(txtDigit.Text, 1, InStr(txtDigit.Text, ".") - 1))
If Len(txtWords.Text) <> 0 Then
txtWords.Text = "Rupees " & txtWords.Text
End If
txtWords.Text = txtWords.Text & " Paise "
strDecimal = printToWords(Mid(txtDigit.Text, InStr(txtDigit.Text, ".") + 1, Len(txtDigit.Text) + 1))
End Sub
Private Sub Form_Load()
arrOneToNinety(0) = ""
arrOneToNinety(1) = "One"
arrOneToNinety(2) = "Two"
arrOneToNinety(3) = "Three"
arrOneToNinety(4) = "Four"
arrOneToNinety(5) = "Five"
arrOneToNinety(6) = "Six"
arrOneToNinety(7) = "Seven"
arrOneToNinety(8) = "Eight"
arrOneToNinety(9) = "Nine"
arrOneToNinety(10) = "Ten"
arrOneToNinety(11) = "Eleven"
arrOneToNinety(12) = "Twelve"
arrOneToNinety(13) = "Thirteen"
arrOneToNinety(14) = "Fourteen"
arrOneToNinety(15) = "Fifteen"
arrOneToNinety(16) = "Sixteen"
arrOneToNinety(17) = "Seventeen"
arrOneToNinety(18) = ""
arrOneToNinety(19) = "Nineteen"
arrOneToNinety(20) = "Twenty"
arrOneToNinety(21) = "Thirty"
arrOneToNinety(22) = "Fourty"
arrOneToNinety(23) = "Fifty"
arrOneToNinety(24) = "Sixty"
arrOneToNinety(25) = "Seventy"
arrOneToNinety(26) = "Eighty"
arrOneToNinety(27) = "Ninety"
End Sub