VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



NUMERIC CURRENCY TO TEXT

by Mr. TGM Programmer - Balayan, Batangas, PHILIPPINES (1 Submission)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 31st July 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

NUMERIC CURRENCY TO TEXT

Rate NUMERIC CURRENCY TO TEXT



Dim WORDVAR, intgr, DECI, _
    Ones(19), Tens(9), Thou(4) As String
Dim ictr, chars, charCntr As Integer

Private Sub Text1_LostFocus()
WORDVAR = ""
If Not IsNumeric(Text1) Then
    Text2.SetFocus
    Text2 = ""
    Text1.SetFocus
    Text1 = ""
    MsgBox "Sorry, your entry is not numeric, entry is not valid"
    Exit Sub
Else
    Text1 = Format(Text1, "#0.000")
End If

chars = Format(Trim(Text1), "000")
charCntr = Len(chars)

If charCntr > 12 Then
    Text2.SetFocus
    Text2 = ""
    Text1.SetFocus
    Text1 = ""
    MsgBox "Entry out of range..."
    Exit Sub
End If

If Len(Trim(Text1)) = 0 Then
    Text2 = "Zero"
    Exit Sub
End If

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"

Tens(1) = "Ten"
Tens(2) = "Twenty"
Tens(3) = "Thirty"
Tens(4) = "Fourty"
Tens(5) = "Fifty"
Tens(6) = "Sixty"
Tens(7) = "Seventy"
Tens(8) = "Eighty"
Tens(9) = "Ninety"

Thou(3) = "Thousand "
Thou(2) = "Million "
Thou(1) = "Billion "
Thou(4) = ""

intgr = RTrim(LTrim(Str(Text1)))

If InStr(intgr, ".") <> 0 Then
    intgr = Left(intgr, InStr(intgr, ".") - 1)
End If

intgr = Right("000000000000" & intgr, 12)
ictr = 3

For ictr = 1 To 12 Step 3
    DECI = Mid(intgr, ictr, 3)
    
    If DECI <> "000" Then
        If Left(DECI, 1) <> "0" Then
            WORDVAR = WORDVAR & Ones(Val(Left(DECI, 1))) & " Hundred"
        End If
    
        If Val(Right(DECI, 2)) <= 19 Then
            WORDVAR = WORDVAR & " " & Ones(Val(Right(DECI, 2))) & ""
        Else
            WORDVAR = WORDVAR & " " & Tens(Val(Mid(DECI, 2, 1))) & " " & Ones(Val(Right(DECI, 1))) & ""
        End If
        WORDVAR = WORDVAR & " " & Thou((ictr - 1) / 3 + 1) & ""
    End If
Next

intgr = RTrim(LTrim(Str(Text1)))
If InStr(intgr, ".") <> 0 Then
    DECI = Right(intgr, (Len(intgr) - InStr(intgr, ".")))
    DECI = "." + DECI
    DECI = Format(DECI, ".00")
    DECI = Mid(DECI, 2, 2)
Else
    DECI = "00"
End If
Text2.SetFocus
Text2 = ""
Text2 = WORDVAR & IIf(Val(DECI) > 0, "& " & Left(DECI & "00", 2) & "/100", "") & " Only."
Text1.SetFocus
Text1 = Format(Text1, "0,00.000")
'Text2.SetFocus
'Text2.Text = ""
'x = 0
'y = 0
'TxtCnvrtd = ""
'tmpString1 = ""
'tmpString2 = ""
'tmpString3 = ""
'Converter
End Sub



Download this snippet    Add to My Saved Code

NUMERIC CURRENCY TO TEXT Comments

No comments have been posted about NUMERIC CURRENCY TO TEXT. Why not be the first to post a comment about NUMERIC CURRENCY TO TEXT.

Post your comment

Subject:
Message:
0/1000 characters