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
Convertion of numeric number into text, capable of...
Author:
Alvin O. Magtibay
E-mail:
Click to e-mail author
Submitted:
10/19/2002
Version:
VB4
Compatibility:
VB4, VB5, VB6
Category:
Miscellaneous
Views:
11668
Convertion of numeric number into text, capable of converting upto 999,999,999,999,999.00, or larger depending on the array declared. The "Peso" here is the currency that we use in our country, change it as you please. Put a control Text1, Text2 and a commandbutton.
Declarations:
Dim NoArray() As String Dim ArrayOnes, ArrayTens, ArrayHundreds, ArrayOthers, ArrayMoreTen
Code:
Dim NoArray() As String Dim ArrayOnes, ArrayTens, ArrayHundreds, ArrayOthers, ArrayMoreTen Private Sub Command1_Click() Dim getpos As Integer, GetAllCentavo As String Text2.Text = vbNullString 'set text2 to null Text1.Text = Format(Val(Text1.Text), "###,###,###,###,###.00") 'format text1 getpos = InStr(1, Text1.Text, ".") 'get the position of "." GetAllCentavo = Mid(Text1.Text, getpos + 1, Len(Text1.Text)) 'get centavo value by determining the position of the "." Text2.Text = " " + GetAllCentavo + "/100" 'display on text the centavo value with "/100" If getpos <> 0 Then GetAllPeso = Mid(Text1.Text, 1, getpos - 1) Text2.Text = ConvertPeso(Mid(Text1.Text, 1, getpos - 1)) & " " & GetAllCentavo & "/100" ' get peso value from the first position to the position of "." less one Else 'GetAllPeso = Text1.Text Text2.Text = ConvertPeso(Text1.Text) & " " & GetAllCentavo & "/100" 'if there is no "." get all value as peso value End If 'ConvertPeso 'call procedure End Sub Private Sub Form_Load() ArrayOnes = Array("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine") ArrayTens = Array("Ten", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety") ArrayMoreTen = Array("Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen") ArrayHundreds = Array("One Hunderd", "Two Hundred", "Three Hundred", "Four Hundred", "Five Hundred", "Six Hundred", "Seven Hundred", "Eight Hundred", "Nine Hundred") ArrayOthers = Array("Pesos", "Thousand", "Million", "Billion", "Thrillion") End Sub Function ConvertPeso(GetAllPeso As String) As String Dim getpos As Integer, GetNo As Integer, WhatPos As Integer, CountComa As Integer Dim getstring As String getpos = 1 'initialize getpos to 1 getstring = GetAllPeso 'get peso value from GetAllPeso variable If getpos <> 0 Then Do While getpos <> 0 getpos = InStr(1, getstring, ",") 'find the position of "," CountComa = CountComa + 1 'count # of comas ReDim Preserve NoArray(CountComa) 'redim array with CountComa value If getpos <> 0 Then NoArray(CountComa) = Mid(getstring, 1, getpos - 1) 'put concatinated #(s) to array 'concatinated value = all #s within the starting position 'till the current postion of "," Else NoArray(CountComa) = getstring 'put value from getstring to NoArray End If getstring = Mid(getstring, getpos + 1, Len(getstring)) 'get value getstring excluding the #(s) you put to the array Loop WhatPos = 1 On Error Resume Next 'error will occur if zero will be assigned to variable GetNo 'GetNo is used to get the word-convertion of a certain # to a certain array Do While CountComa <> 0 getstring = Val(NoArray(CountComa)) 'get the value from array for convertion to words If CInt(getstring) = 0 Then GoTo proceedLoop 'if 0 then proceed to the procedure below Else ConvertPeso = ArrayOthers(WhatPos - 1) + " " + ConvertPeso 'get convertion from array, indicated by the value 'accuired from variable WhatPos End If If Len(getstring) = 1 Then 'if single digit # will be converted 'ex: 1 , 2, 3 ,5 ,8 ,etc GetNo = CInt(getstring) 'CInt(Right(getstring, 1)) ConvertPeso = ArrayOnes(GetNo - 1) + " " + ConvertPeso 'get convertion from array, indicated by the value 'accuired from variable GetNo GoTo proceedLoop 'proceed to procedure below ElseIf Len(getstring) = 2 Then 'two digit # will be converted 'ex: 12, 17, 28, 11, 29, etc. If CInt(getstring) >= 10 And CInt(getstring) <= 19 Then 'if more than 9 or less than 20 If CInt(getstring) = 0 Then 'to check for zero values GoTo proceedLoop End If GetNo = CInt(Right(getstring, 1)) 'get the first digit # ConvertPeso = ArrayMoreTen(GetNo) + " " + ConvertPeso 'get convertion from array, indicated by the value 'accuired from variable GetNo GoTo proceedLoop ' then proceed to statements below End If If CInt(getstring) = 0 Then GoTo proceedLoop 'if zero, then proceed to statements below End If GetNo = CInt(Right(getstring, 1)) 'get ast digit # ConvertPeso = ArrayOnes(GetNo - 1) + " " + ConvertPeso 'get convertion from array, indicated by the value 'accuired from variable GetNo GetNo = CInt(Left(getstring, 1)) 'get the first digit # ConvertPeso = ArrayTens(GetNo - 1) + " " + ConvertPeso 'get convertion from array, indicated by the value 'accuired from variable GetNo CountComa = 0 Exit Function Else 'if lenght of getstring is more than two 'ex: 100,123,345,678,etc GetNo = CInt(Right(getstring, 2)) 'get the two last digit #(s) 'to know whether the value belonged to the 20s,30s,40s or 'belonged to 11 - 19 value If (CInt(GetNo) >= 10 And CInt(GetNo) <= 19) Then 'if more than 9 or less than 20 getstring = Val(getstring) 'convert to value type If CInt(getstring) = 0 Then 'if zero, then proceed to statements below GoTo proceedLoop End If If Len(getstring) = 3 Then 'if lenght of getstring is more than two 'ex: 100,123,345,678,etc GetNo = CInt(Right(getstring, 1)) 'get ast digit # ConvertPeso = ArrayMoreTen(GetNo) + " " + ConvertPeso 'get convertion from array, indicated by the value 'accuired from variable GetNo GetNo = CInt(Left(getstring, 1)) ConvertPeso = ArrayHundreds(GetNo - 1) + " " + ConvertPeso 'get convertion from array, indicated by the value 'accuired from variable GetNo Else GetNo = CInt(Right(getstring, 1)) ConvertPeso = ArrayMoreTen(GetNo) + " " + ConvertPeso End If GoTo proceedLoop End If proceed3Lenght: GetNo = CInt(Right(getstring, 1)) 'get last # ConvertPeso = ArrayOnes(GetNo - 1) + " " + ConvertPeso 'get convertion from array, indicated by the value 'accuired from variable GetNo GetNo = CInt(Mid(getstring, 2, 1)) 'get middle # ConvertPeso = ArrayTens(GetNo - 1) + " " + ConvertPeso 'get convertion from array, indicated by the value 'accuired from variable GetNo GetNo = CInt(Left(getstring, 1)) 'get first # ConvertPeso = ArrayHundreds(GetNo - 1) + " " + ConvertPeso 'get convertion from array, indicated by the value 'accuired from variable GetNo End If proceedLoop: CountComa = CountComa - 1 'decrement CountComa WhatPos = WhatPos + 1 'specify the next position of "," to indicate wheter 'to display hundreds, thousand, millions, etc Loop CountComa = 0 End If End Function Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Call Command1_Click End If End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement