Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Number to Text conversion
Author:
Dinesh G
E-mail:
Click to e-mail author
Submitted:
4/25/2008
Version:
VB6
Compatibility:
VB6
Category:
Forms
Views:
17810
This function converts number to text in the range 0.00 to 999999999.99
Declarations:
You can freely use this code in your own applications, but you may not reproduce or publish this code on any web site, online service, or distribute as source on any media without express permission.
Code:
'To a form add one text box (Text1) and one label (Label1) and one command button (command1). Copy the following form code and past in the form. Just run.... Private Sub Command1_Click() Label1.Caption = Number2Word(Val(Text1.Text)) End Sub Private Function Number2Word(ByVal pNum As Double) As String '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Copyright ©2007-2008 Simple Soft Solutions, Dinesh G Nair, All Rights Reserved. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Distribution: You can freely use this code in your own ' applications, but you may not reproduce ' or publish this code on any web site, ' online service, or distribute as source ' on any media without express permission. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Module Name: NumberToText 'Programmer: Dinesh G 'Date Released: April 25, 2008 'Date Modified: April 25, 2008 'Copyright 2008 by Dinesh G Nair (All rights reserved) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' On Error GoTo ErrHdl Dim ar1(19) As String Dim ar2(10) As String Dim ar3(5) As String ar1(0) = "" ar1(1) = "One" ar1(2) = "Two" ar1(3) = "Three" ar1(4) = "Four" ar1(5) = "Five" ar1(6) = "Six" ar1(7) = "Seven" ar1(8) = "Eight" ar1(9) = "Nine" ar1(10) = "Ten" ar1(11) = "Eleven" ar1(12) = "Twelve" ar1(13) = "Thirteen" ar1(14) = "Fourteen" ar1(15) = "Fifteen" ar1(16) = "Sixteen" ar1(17) = "Seventeen" ar1(18) = "Eighteen" ar1(19) = "Ninteen" ar2(1) = "Ten" ar2(2) = "Twenty" ar2(3) = "Thirty" ar2(4) = "Fourty" ar2(5) = "Fifty" ar2(6) = "Sixty" ar2(7) = "Seventy" ar2(8) = "Eighty" ar2(9) = "Ninty" ar3(0) = "" ar3(1) = "Hundred" ar3(2) = "Thousand" ar3(3) = "Lakh" ar3(4) = "Crore" Dim tmpNum As Double Dim tmpInt As Long Dim tmpDml As Integer Dim strWord As String Dim strWordpart As String Dim tmppart As Integer Dim lcount As Integer tmpNum = pNum tmpInt = Int(tmpNum) tmpDml = (tmpNum - tmpInt) * 100 'Integer conversion If tmpInt < 0 Or tmpInt > 999999999 Then MsgBox "Convertible range is 0.00 to 999999999.99 only" & vbCrLf & "Sorry for the inconvenience..." Exit Function End If If tmpInt = 0 Then strWord = "Zero" ElseIf tmpInt < 20 Then strWord = ar1(tmpInt) Else lcount = -1 Do While tmpInt > 0 strWordpart = "" If lcount < 0 Or lcount > 0 Then tmppart = Right(Trim(Str(tmpInt)), 2) If Val(tmpInt) >= 10 Then tmpInt = Val(Left(Trim(Str(tmpInt)), Len(Trim(Str(tmpInt))) - 2)) Else tmpInt = Val(Left(Trim(Str(tmpInt)), Len(Trim(Str(tmpInt))) - 1)) End If ElseIf lcount = 0 Then tmppart = Right(Trim(Str(tmpInt)), 1) tmpInt = Val(Left(Trim(Str(tmpInt)), Len(Trim(Str(tmpInt))) - 1)) End If lcount = lcount + 1 If tmppart < 20 Then strWordpart = ar1(tmppart) Else strWordpart = ar2(Int(tmppart / 10)) & " " & ar1(tmppart Mod 10) End If If Not Trim(strWordpart) = "" Then strWord = strWordpart & " " & ar3(lcount) & " " & strWord End If Loop End If strWord = "Rs. " & strWord ' Decimal part conversion ' This will be added to string only if paise part exists. strWordpart = "" If tmpDml < 20 Then strWordpart = ar1(tmpDml) Else strWordpart = ar2(Int(tmpDml / 10)) & " " & ar1(tmpDml Mod 10) End If If Not Trim(strWordpart) = "" Then strWord = Trim(strWord) & " and " & strWordpart & " paise Only" Else strWord = Trim(strWord) & " Only" End If ' Retun final output Number2Word = strWord Exit Function ErrHdl: MsgBox "value out of scope" Number2Word = "" End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement