VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code will convert a number up to 10 digits in words

by Pankaj (1 Submission)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 6th December 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code will convert a number up to 10 digits in words

API Declarations


Dim getw As String

Rate This code will convert a number up to 10 digits in words





Private Sub Command1_Click()
If Val(Text1.Text) <> 0 Then
    MsgBox ConvertNumerToWords(Text1.Text), vbInformation, "Conversion"
Else
    MsgBox "Zero"
End If
End Sub

Private Function GetDivideby(len1 As Byte) As Long
    Select Case len1
        Case 1, 2: GetDivideby = 1
        Case 3, 3: GetDivideby = 100: getw = " Hundred"
        Case 4, 5: GetDivideby = 1000: getw = " Thousand"
        Case 6, 7: GetDivideby = 100000: getw = " Lac"
        Case 8, 9: GetDivideby = 10000000: getw = " Crore"
    End Select
End Function

Private Function ConvertNumerToWords(NumberToConvert As String) As String
Dim divideby As Long, Remainder As Long, Quotient As Long, dividend As Long
Dim Quotient1 As String, Remainder1 As String, dividend1 As String, textcontent() As String
    
    textcontent = Split(NumberToConvert, ".")
    Remainder = Val(textcontent(0))
    Remainder1 = Remainder
    Do While Val(Remainder1) > 0
        dividend = Remainder
        divideby = GetDivideby(Len(Remainder1))
        
        Quotient = dividend \ divideby
        Quotient1 = Quotient
        
        wordings Quotient1
        
        words = words & getw
        getw = ""
        Remainder = dividend Mod divideby
        Remainder1 = Remainder
    Loop
    
    If UBound(textcontent) = 1 Then
        If Len(textcontent(1)) = 1 Then
            words = words & " Rupees and" & Getsinglenumber(Val(textcontent(1))) & " Paise"
        ElseIf Len(textcontent(1)) = 2 Then
            words = words & " Rupees and" & Getty(Left(textcontent(1), 1))
            words = words & Getsinglenumber(Right(textcontent(1), 1)) & " Paise"
        End If
    End If
    
    ConvertNumerToWords = words
    words = ""
End Function

Private Function wordings(common As String) As String
    If Val(common) < 20 Then
        words = words & Getsinglenumber(Val(common))
    Else
        words = words & Getty(Left(common, 1))
        words = words & Getsinglenumber(Right(common, 1))
    End If
End Function

Private Function Getsinglenumber(number As Long) As String

    Select Case number
        Case 1:  Getsinglenumber = " One"
        Case 2:  Getsinglenumber = " Two"
        Case 3:  Getsinglenumber = " Three"
        Case 4:  Getsinglenumber = " Four"
        Case 5:  Getsinglenumber = " Five"
        Case 6:  Getsinglenumber = " Six"
        Case 7:  Getsinglenumber = " Seven"
        Case 8:  Getsinglenumber = " Eight"
        Case 9:  Getsinglenumber = " Nine"
        Case 10: Getsinglenumber = " Ten"
        Case 11: Getsinglenumber = " Eleven"
        Case 12: Getsinglenumber = " Twelve"
        Case 13: Getsinglenumber = " Thirteen"
        Case 14: Getsinglenumber = " Fourteen"
        Case 15: Getsinglenumber = " Fifteen"
        Case 16: Getsinglenumber = " Sixteen"
        Case 17: Getsinglenumber = " Seventeen"
        Case 18: Getsinglenumber = " Eighteen"
        Case 19: Getsinglenumber = " Nineteen"
    End Select
End Function

Private Function Getty(number As Long) As String
    Select Case number
        Case 2: Getty = " Twenty"
        Case 3: Getty = " Thirty"
        Case 4: Getty = " Forty"
        Case 5: Getty = " Fifty"
        Case 6: Getty = " Sixty"
        Case 7: Getty = " Seventy"
        Case 8: Getty = " Eighty"
        Case 9: Getty = " Ninety"
    End Select
End Function

Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then Command1_Click
    If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 46 And KeyAscii <> 8 Then KeyAscii = 0
    If InStr(1, Text1.Text, ".") > 0 And KeyAscii = 46 Then KeyAscii = 0
End Sub



Download this snippet    Add to My Saved Code

This code will convert a number up to 10 digits in words Comments

No comments have been posted about This code will convert a number up to 10 digits in words. Why not be the first to post a comment about This code will convert a number up to 10 digits in words.

Post your comment

Subject:
Message:
0/1000 characters