Spellnumber


09 August 2022 If we enter a number it will convert into individual strings and display in same order.

Ex: If I enter 564 then the output should be FIVE SIX FOUR.

So can anyone modify this code to get this result.



Function SpellNumber(amt As Variant) As Variant

Dim FIGURE As Variant
Dim LENFIG As Integer
Dim i As Integer
Dim WORDs(19) As String
Dim tens(9) As String
WORDs(1) = "ONE"
WORDs(2) = "TWO"
WORDs(3) = "THREE"
WORDs(4) = "FOUR"
WORDs(5) = "FIVE"
WORDs(6) = "SIX"
WORDs(7) = "SEVEN"
WORDs(8) = "EIGHT"
WORDs(9) = "NINE"
WORDs(10) = "TEN"
WORDs(11) = "ELEVEN"
WORDs(12) = "TWELVE"
WORDs(13) = "THIRTEEN"
WORDs(14) = "FOURTEEN"
WORDs(15) = "FIFTEEN"
WORDs(16) = "SIXTEEN"
WORDs(17) = "SEVENTEEN"
WORDs(18) = "EIGHTEEN"
WORDs(19) = "NINETEEN"
tens(2) = "TWENTY "
tens(3) = "THIRTY "
tens(4) = "FOURTY "
tens(5) = "FIFTY "
tens(6) = "SIXTY "
tens(7) = "SEVENTY "
tens(8) = "EIGHTY "
tens(9) = "NINETY "
FIGURE = amt
FIGURE = Format(FIGURE, "FIXED")
FIGLEN = Len(FIGURE)
If FIGLEN 1 Then
ElseIf Val(Left(FIGURE, 9)) = 1 Then
End If
For i = 1 To 3
If Val(Left(FIGURE, 2)) 0 Then
SpellNumber = SpellNumber & WORDs(Val(Left(FIGURE, 2)))
ElseIf Val(Left(FIGURE, 2)) > 19 Then
SpellNumber = SpellNumber & tens(Val(Left(FIGURE, 1)))
SpellNumber = SpellNumber & WORDs(Val(Right(Left(FIGURE, 2), 1)))
End If
If i = 1 And Val(Left(FIGURE, 2)) > 0 Then
SpellNumber = SpellNumber & " CRORE "
ElseIf i = 2 And Val(Left(FIGURE, 2)) > 0 Then
SpellNumber = SpellNumber & " LAKH "
ElseIf i = 3 And Val(Left(FIGURE, 2)) > 0 Then
SpellNumber = SpellNumber & " THOUSAND "
End If
FIGURE = Mid(FIGURE, 3)
Next i
If Val(Left(FIGURE, 1)) > 0 Then
SpellNumber = SpellNumber & WORDs(Val(Left(FIGURE, 1))) + " HUNDRED "
End If
FIGURE = Mid(FIGURE, 2)
If Val(Left(FIGURE, 2)) 0 Then
SpellNumber = SpellNumber & WORDs(Val(Left(FIGURE, 2)))
ElseIf Val(Left(FIGURE, 2)) > 19 Then
SpellNumber = SpellNumber & tens(Val(Left(FIGURE, 1)))
SpellNumber = SpellNumber & WORDs(Val(Right(Left(FIGURE, 2), 1)))
End If
FIGURE = Mid(FIGURE, 4)
If Val(FIGURE) > 0 Then
SpellNumber = SpellNumber & " PAISE "
If Val(Left(FIGURE, 2)) 0 Then
SpellNumber = SpellNumber & WORDs(Val(Left(FIGURE, 2)))
ElseIf Val(Left(FIGURE, 2)) > 19 Then
SpellNumber = SpellNumber & tens(Val(Left(FIGURE, 1)))
SpellNumber = SpellNumber & WORDs(Val(Right(Left(FIGURE, 2), 1)))
End If
End If
FIGURE = amt
FIGURE = Format(FIGURE, "FIXED")
If Val(FIGURE) > 0 Then
SpellNumber = SpellNumber & " ONLY "
End If
End Function



You need to be the querist or approved CAclub expert to take part in this query .
Click here to login now



Unanswered Queries