Hello Everybody,
Firstly I thank all of whom have helped in finding a code for converting numbers to string.
I here am giving a totally different code which works perfectly till 9 Crores
The Code is ---
Option Compare Database
Public Function Spell(InVal) As String
Dim Ones(100) As Variant
Dim X(10) As Variant
Dim Real, Imax, Idigit(30), J, I1
Dim Value As String
Value = ""
For i = 1 To Imax
Idigit(i) = Real - 10 * Int(Real / 10)
Real = Int(Real / 10)
Next i
For i = 1 To Imax
I1 = Imax - i + 1
J = Idigit(I1)
If I1 <> 9 Then GoTo 60
If J <> 1 Then GoTo 65
J = 10 + Idigit(I1 - 1)
i = i + 1
I1 = I1 - 1
GoTo 99
65:
J = 10 * J
If Idigit(I1) = 0 And Idigit(I1 - 1) = 0 Then
i = i + 1
GoTo 100
End If
60:
If I1 <> 7 Then GoTo 80
If J <> 1 Then GoTo 85
J = 10 + Idigit(I1 - 1)
i = i + 1
I1 = I1 - 1
GoTo 99
85:
J = 10 * J
If Idigit(I1) = 0 And Idigit(I1 - 1) = 0 Then
i = i + 1
GoTo 100
End If
80:
If I1 <> 5 Then GoTo 90
If J <> 1 Then GoTo 75
J = 10 + Idigit(I1 - 1)
i = i + 1
I1 = I1 - 1
GoTo 99
75:
J = 10 * J
If Idigit(I1) = 0 And Idigit(I1 - 1) = 0 Then
i = i + 1
GoTo 100
End If
90:
If I1 <> 3 Then GoTo 95
If Idigit(I1) = 0 Then GoTo 100
95:
If I1 <> 2 Then GoTo 99
If J <> 1 Then GoTo 98
J = 10 + Idigit(I1 - 1)
i = i + 1
I1 = I1 - 1
GoTo 99
98:
J = 10 * J
99:
Value = Value + Ones(J) + X(I1)
100:
Next i
Spell = Value
End Function
---
If any bugs r present plz let me know.
Thankz
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.