VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Converts numbers into words

by Ashwini Sharad Pore (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 28th December 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Converts numbers into words

Rate Converts numbers into words



' For Queries you can contact at [email protected]

Private Sub txt_KeyPress(KeyAscii As Integer)
Dim str As String
str = "0123456789."
If InStr(str, Chr(KeyAscii)) = 0 And KeyAscii <> 8 Then
    KeyAscii = 0
End If
End Sub

Private Sub txt_LostFocus()
Dim Intgr As Double
Dim Fract As Double

Intgr = Int(txt)
Fract = Format((txt - Intgr) * 100, "0#")
If Val(txt) > 2146999999 Then
    MsgBox ("Data out of range .Pl enter  values upto 2,14,69,99,999 only")
    Exit Sub
End If

If InStr(1, txt, ".") = InStrRev(txt, ".", -1, 1) Then
    If Val(Intgr) = 0 Then
        txtWords = ConToWords(Fract) + " Paisa only."
    End If
    If Val(Fract) = 0 Then
        txtWords = ConToWords(Intgr) + " Rs only."
    End If
    If Val(Intgr) <> 0 And Val(Fract) <> 0 Then
        txtWords = ConToWords(Intgr) + " Rs. And " + ConToWords(Fract) + " Paisa Only"
    End If
Else
    MsgBox ("Incorrect Number")
    Exit Sub
End If
End Sub

Private Function ConToWords(num As Double) As String
Dim Remn As Double
Dim Quo As Double
Select Case Len(Trim(num))
    Case 1
        Select Case num
            Case 1:
                ConToWords = "One"
            Case 2:
                ConToWords = "Two"
            Case 3:
                ConToWords = "Three"
            Case 4:
                ConToWords = "Four"
            Case 5:
                ConToWords = "Five"
            Case 6:
                ConToWords = "Six"
            Case 7:
                ConToWords = "Seven"
            Case 8:
                ConToWords = "Eight"
            Case 9:
                ConToWords = "Nine"
        End Select
    Case 2
        Select Case num
            Case 10:
                ConToWords = "Ten"
            Case 11:
                ConToWords = "Eleven"
            Case 12:
                ConToWords = "Twelve"
            Case 13:
                ConToWords = "Thirteen"
            Case 14:
                ConToWords = "Forteen"
            Case 15:
                ConToWords = "Fifteen"
            Case 16:
                ConToWords = "Sixteen"
            Case 17:
                ConToWords = "Seventeen"
            Case 18:
                ConToWords = "Eighteen"
            Case 19:
                ConToWords = "Ninteen"
            Case Is >= 20 And num <= 99
                ConToWords = TwoDigit(num)
        End Select
    Case 3
        Remn = num Mod 100
        Quo = num \ 100
        If Remn <> 0 Then
            ConToWords = ConToWords(Quo) + " Hundred and " + ConToWords(Remn)
        Else
            ConToWords = ConToWords(Quo) + " Hundred  "
        End If
    Case 4, 5
        Remn = num Mod 1000
        Quo = num \ 1000
        ConToWords = ConToWords(Quo) + " Thousand " + ConToWords(Remn)
    Case 6, 7
        Remn = num Mod 100000
        Quo = num \ 100000
        ConToWords = ConToWords(Quo) + " Lakh " + ConToWords(Remn)
    Case Is >= 8
        Remn = num Mod 10000000
        Quo = num \ 10000000
        ConToWords = ConToWords(Quo) + " Crores " + ConToWords(Remn)
End Select
End Function

Private Function TwoDigit(num As Double) As String
Dim Remn As Double
Dim Quo As Double
Remn = num Mod 10
Quo = num \ 10
Select Case Quo
    Case 2:
        TwoDigit = "Twenty"
    Case 3:
        TwoDigit = "Thirty"
    Case 4:
        TwoDigit = "Forty"
    Case 5:
        TwoDigit = "Fifty"
    Case 6:
        TwoDigit = "Sixty"
    Case 7:
        TwoDigit = "Seventy"
    Case 8:
        TwoDigit = "Eighty"
    Case 9:
        TwoDigit = "Ninty"
End Select

Select Case Remn
    Case Is <> 0
          TwoDigit = TwoDigit + ConToWords(Val(Remn))
End Select
End Function


Download this snippet    Add to My Saved Code

Converts numbers into words Comments

No comments have been posted about Converts numbers into words. Why not be the first to post a comment about Converts numbers into words.

Post your comment

Subject:
Message:
0/1000 characters