INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Code for Converting Number to

Converting Number to Strings(Ex - 9 to Nine) by San22
Posted: 10 Apr 02

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

X(1) = ""
X(2) = ""
X(3) = " Hundred "
X(4) = " Thousand "
X(5) = ""
X(6) = " Lakh "
X(7) = ""
X(8) = " Crore "
X(9) = ""

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

Real = Int(InVal)
Imax = Len(Real)

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

Back to Microsoft: Access Tables and Relationships FAQ Index
Back to Microsoft: Access Tables and Relationships Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close