VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Converts upto 9 Numbers into Words (i.e. 100 can be converted in to One Hundred

by Rahul A. Hadgal (1 Submission)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 14th May 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Converts upto 9 Numbers into Words (i.e. 100 can be converted in to "One Hundred"

API Declarations



* Usage
Please the below code into a Module and
call in the following way :
msgbox CnvNum2Words(12345)

Rate Converts upto 9 Numbers into Words (i.e. 100 can be converted in to One Hundred



Dim nAry(0 To 90)
nAry(0) = "Zero"
nAry(1) = "One"
nAry(2) = "Two"
nAry(3) = "Three"
nAry(4) = "Four"
nAry(5) = "Five"
nAry(6) = "Six"
nAry(7) = "Seven"
nAry(8) = "Eight"
nAry(9) = "Nine"
nAry(10) = "Ten"
nAry(11) = "Eleven"
nAry(12) = "Twelve"
nAry(13) = "Thirteen"
nAry(14) = "Fourteen"
nAry(15) = "Fifteen"
nAry(16) = "Sixteen"
nAry(17) = "Seventeen"
nAry(18) = "Eighteen"
nAry(19) = "Nineteen"
nAry(20) = "Twenty"
nAry(30) = "Thirty"
nAry(40) = "Forty"
nAry(50) = "Fifty"
nAry(60) = "Sixty"
nAry(70) = "Seventy"
nAry(80) = "Eighty"
nAry(90) = "Ninty"

word = nValue
j = Len(word)
Dim T As Boolean, U As Boolean, V As Boolean, W As Boolean
T = False
U = False
V = False
W = False
For i = 1 To Len(word)
If j = 9 And Mid(word, i, 1) > 1 Then
rst = rst & " " & nAry(Mid(word, i, 1) & 0)
ElseIf j = 9 And Mid(word, i, 1) = 1 Then
rst = rst & " " & nAry(Mid(word, i, 2)) & " Crore"
U = True
ElseIf j = 9 And Mid(word, i, 1) = 0 Then
rst = rst

ElseIf j = 8 And U = False And Mid(word, i, 1) > 0 Then
rst = rst & " " & nAry(Mid(word, i, 1)) & " Crore"

ElseIf j = 7 And Mid(word, i, 1) > 1 Then
rst = rst & " " & nAry(Mid(word, i, 1) & 0)
T = False
ElseIf j = 7 And Mid(word, i, 1) = 1 Then
rst = rst & " " & nAry(Mid(word, i, 2)) & " Lakh"
T = True
ElseIf j = 7 And Mid(word, i, 1) = 0 Then
rst = rst
T = False

ElseIf j = 6 And T = False And Mid(word, i, 1) = 0 Then
rst = rst & " Lakh"

ElseIf j = 6 And T = False And Mid(word, i, 1) > 0 Then
rst = rst & " " & nAry(Mid(word, i, 1)) & " Lakh"

ElseIf j = 5 And Mid(word, i, 1) > 1 Then
rst = rst & " " & nAry(Mid(word, i, 1) & 0)
W = False
ElseIf j = 5 And Mid(word, i, 1) = 1 Then
rst = rst & " " & nAry(Mid(word, i, 2)) & " Thousand"
W = True
ElseIf j = 5 And Mid(word, i, 1) = 0 Then
rst = rst
W = False
ElseIf j = 4 And W = False And Mid(word, i, 1) = 0 Then
rst = rst & " Thousand"
ElseIf j = 4 And W = False And Mid(word, i, 1) > 0 Then
rst = rst & " " & nAry(Mid(word, i, 1)) & " Thousand"

ElseIf j = 3 And Mid(word, i, 1) > 0 Then
rst = rst & " " & nAry(Mid(word, i, 1)) & " Hundred"
ElseIf j = 3 And Mid(word, i, 1) = 0 Then
rst = rst

ElseIf j = 2 And Mid(word, i, 1) > 1 And Len(word) > 2 Then
rst = rst & " and " & nAry(Mid(word, i, 1) & 0)
V = True
ElseIf j = 2 And Mid(word, i, 1) > 1 Then
rst = rst & " " & nAry(Mid(word, i, 1) & 0)
V = True
ElseIf j = 2 And Mid(word, i, 1) = 1 And Len(word) > 2 Then
rst = rst & " and " & nAry(Mid(word, i, 2))
V = True
Exit For
ElseIf j = 2 And Mid(word, i, 1) = 1 Then
rst = rst & " " & nAry(Mid(word, i, 2))
V = True
Exit For
ElseIf j = 2 And Mid(word, i, 1) = 0 Then
rst = rst
V = False

ElseIf j = 1 And Mid(word, i, 1) > 0 Then
rst = rst & " " & nAry(Mid(word, i, 1))
Exit For

ElseIf j = 1 And Mid(word, i, 1) > 0 And V = False Then
rst = rst & " and " & nAry(Mid(word, i, 1))
Exit For
End If
j = j - 1
Next
CnvNum2Words = LTrim(rst)
End Function


Download this snippet    Add to My Saved Code

Converts upto 9 Numbers into Words (i.e. 100 can be converted in to One Hundred Comments

No comments have been posted about Converts upto 9 Numbers into Words (i.e. 100 can be converted in to One Hundred. Why not be the first to post a comment about Converts upto 9 Numbers into Words (i.e. 100 can be converted in to One Hundred.

Post your comment

Subject:
Message:
0/1000 characters