VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Converts your number to TEXT (Example 12345 To Twelve Thousand Three Hundred Fourty Five) Userful f

by Rahul Sardesai And Keshav Mantha (1 Submission)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 9th May 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Converts your number to TEXT (Example 12345 To Twelve Thousand Three Hundred Fourty Five) Userful for BANKING And Commercial Operations......

API Declarations


Paste The Code Below In A Module.....
And Start Using It

Rate Converts your number to TEXT (Example 12345 To Twelve Thousand Three Hundred Fourty Five) Userful f



Option Explicit
'//////////////////////////////////////////////////////////////
'// Author: Rahul Sardesai & Keshav Mantha
'// Copany: Credit Card Consultants Private Limited
'//////////////////////////////////////////////////////////////

Public Function NumberToText(nParam As Long) As String
    '
    If nParam = 0 Then
        NumberToText = "Zero"
        Exit Function
    End If
    '
    Dim iCtr    As Integer
    Dim iPos    As Integer
    Dim sNumber As String
    '
    sNumber = Convert(Right(Trim(Str(nParam)), 3), iPos)
    '
    For iCtr = Len(Trim(Str(nParam))) - 3 To 1 Step -2
        iPos = iPos + 1
        sNumber = Convert(Right(Left(Trim(Str(nParam)), iCtr), 2), iPos) & sNumber
    Next iCtr
    '
    NumberToText = UCase(Trim(sNumber))
    '
End Function

Private Function Convert(nNumber As Integer, nPos As Integer) As String
    '
    Dim sReturnText
    '
    Select Case nPos
        Case 0: sReturnText = Finalize(nNumber, nPos)
        Case 1: sReturnText = Finalize(nNumber, nPos)
        Case 2: sReturnText = Finalize(nNumber, nPos)
        Case 3: sReturnText = Finalize(nNumber, nPos)
    End Select
    '
    Convert = sReturnText
    '
End Function

Private Function Finalize(nNum As Integer, nWord As Integer) As String
    '
    Dim sNum1 As String * 1
    Dim sNum2 As String * 2
    Dim sTmp  As String
    '
    If nNum >= 100 Then
        sNum1 = Mid(Trim(Str(nNum)), 1, 1)
        sNum2 = Mid(Trim(Str(nNum)), 2, 2)
    Else
        sNum1 = ""
        sNum2 = Mid(Trim(Str(nNum)), 1, 2)
    End If
    '
    Select Case sNum1
        Case "1": sTmp = "One Hundred "
        Case "2": sTmp = "Two Hundred "
        Case "3": sTmp = "Three Hundred "
        Case "4": sTmp = "Four Hundred "
        Case "5": sTmp = "Five Hundred "
        Case "6": sTmp = "Six Hundred "
        Case "7": sTmp = "Seven Hundred "
        Case "8": sTmp = "Eight Hundred "
        Case "9": sTmp = "Nine Hundred "
    End Select
    '
    If Len(Trim(sNum2)) = 1 Then sNum2 = "0" & Trim(sNum2)
    '
    Select Case Left(sNum2, 1)
        Case "0":
            Select Case Right(sNum2, 1)
                Case "0": sTmp = sTmp + ""
                Case "1": sTmp = sTmp + "One "
                Case "2": sTmp = sTmp + "Two "
                Case "3": sTmp = sTmp + "Three "
                Case "4": sTmp = sTmp + "Four "
                Case "5": sTmp = sTmp + "Five "
                Case "6": sTmp = sTmp + "Six "
                Case "7": sTmp = sTmp + "Seven "
                Case "8": sTmp = sTmp + "Eight "
                Case "9": sTmp = sTmp + "Nine "
            End Select
        Case "1":
            Select Case Right(sNum2, 1)
                Case "0": sTmp = sTmp + "Ten "
                Case "1": sTmp = sTmp + "Eleven "
                Case "2": sTmp = sTmp + "Twelve "
                Case "3": sTmp = sTmp + "Thirteen "
                Case "4": sTmp = sTmp + "Fourteen "
                Case "5": sTmp = sTmp + "Fifteen "
                Case "6": sTmp = sTmp + "Sixteen "
                Case "7": sTmp = sTmp + "Seventenn "
                Case "8": sTmp = sTmp + "Eighteen "
                Case "9": sTmp = sTmp + "Nineteen "
            End Select
        Case "2": sTmp = sTmp + "Twenty " & SingleNumber(Val(Right(sNum2, 1)))
        Case "3": sTmp = sTmp + "Thirty " & SingleNumber(Val(Right(sNum2, 1)))
        Case "4": sTmp = sTmp + "Fourty " & SingleNumber(Val(Right(sNum2, 1)))
        Case "5": sTmp = sTmp + "Fifty " & SingleNumber(Val(Right(sNum2, 1)))
        Case "6": sTmp = sTmp + "Sixty " & SingleNumber(Val(Right(sNum2, 1)))
        Case "7": sTmp = sTmp + "Seventy " & SingleNumber(Val(Right(sNum2, 1)))
        Case "8": sTmp = sTmp + "Eighty " & SingleNumber(Val(Right(sNum2, 1)))
        Case "9": sTmp = sTmp + "Ninety " & SingleNumber(Val(Right(sNum2, 1)))
    End Select
    '
    Select Case nWord
        Case 0: Finalize = sTmp
        Case 1: If Trim(sTmp) = "" Then Finalize = "" Else Finalize = sTmp & "Thousand "
        Case 2: If Trim(sTmp) = "" Then Finalize = "" Else Finalize = sTmp & "Lacks "
        Case 3: If Trim(sTmp) = "" Then Finalize = "" Else Finalize = sTmp & "Crore "
    End Select
    '
End Function

Private Function SingleNumber(bNum As Integer) As String
    '
    Select Case bNum
        Case 0: SingleNumber = ""
        Case 1: SingleNumber = "One "
        Case 2: SingleNumber = "Two "
        Case 3: SingleNumber = "Three "
        Case 4: SingleNumber = "Four "
        Case 5: SingleNumber = "Five "
        Case 6: SingleNumber = "Six "
        Case 7: SingleNumber = "Seven "
        Case 8: SingleNumber = "Eight "
        Case 9: SingleNumber = "Nine "
    End Select
    '
End Function


Download this snippet    Add to My Saved Code

Converts your number to TEXT (Example 12345 To Twelve Thousand Three Hundred Fourty Five) Userful f Comments

No comments have been posted about Converts your number to TEXT (Example 12345 To Twelve Thousand Three Hundred Fourty Five) Userful f. Why not be the first to post a comment about Converts your number to TEXT (Example 12345 To Twelve Thousand Three Hundred Fourty Five) Userful f.

Post your comment

Subject:
Message:
0/1000 characters