

 Thread Tools  Search this Thread 
#1
 
 
How to convert vb .text to number format
I have the requirement to convert the word 2007 text file and need to have visual basic code for converting a selected text to a number, and a number to text? If it would be possible then please let me, i also expect answer descriptive as well. Thanks for those who help.. 
#2
 
 
Re: How to convert vb .text to number format
The number to be converted to word text can be a numeric value or a string.

#3
 
 
Re: How to convert vb .text to number format
To convert String to Number i will suggest you to use the Val function which will convert a string to a decimal number.If you need a formula to simply change numbers to text, use =concatenate([Cell#]). The Val function is not locale aware, so it will not recognize comma decimal separators in countries where this is used, such as "1,000,000". following is the vb code which will allows you to do the conversion. Quote:

#4
 
 
Re: How to convert vb .text to number format Code: found = InStrRev(Text1.Text, Chr(10), pos, 0) 
#5
 
 
Re: How to convert vb .text to number format
' Convert a number between 0 and 999 into words. Private Function numbers(ByVal num As Integer) As String Static onetonineteen() As String = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen", "Nineteen"} Static tens() As String = {"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety "} Static thousand() As String = {" Thousand "} Dim place As Integer Dim valid As Boolean = True Dim result As String = "" 'http://www.vbhelper.com/howto_net_dollars_to_words.html is somewhat used here ' Handle the hundreds digit. If txtAmount.Text.Length = 0 Then MessageBox.Show("Please enter an amount.") valid = False End If If num > 99 Then place = CInt(num / 100) num = num Mod 100 result = onetonineteen(place) & " Hundred" End If ' If num = 0, we have hundreds only. If num = 0 Then Return result.Trim() ' See if the rest is less than 20. If num < 20 Then ' Look up the correct name. result &= " " & onetonineteen(num) Else ' Handle the tens digit. place = num \ 10 num = num Mod 10 result &= " " & tens(place  2) ' Handle the final digit. If num > 0 Then result &= " " & onetonineteen(num) valid = True End If If result.EndsWith(", ") Then result = result.Substring(0, result.Length  2) End If If valid = True Then Me.Hide() End If If valid = False Then txtAmount.Text = "" End If End If Return result.Trim() End Function 
#6
 
 
Re: How to convert vb .text to number format
Private Function NumberToString(ByVal num As Double) As _ String ' Remove any fractional part. num = Int(num) ' If the number is 0, return zero. If num = 0 Then Return "zero" Static groups() As String = {"", "thousand", "million", _ "billion", "trillion", "quadrillion", "?", "??", _ "???", "????"} Dim result As String = "" Dim valid As Boolean = True ' Process the groups, smallest first. Dim quotient As Double Dim remainder As Integer Dim group_num As Integer = 0 Do While num > 0 And num < 9999.99 ' Get the next group of three digits. quotient = Int(num / 1000) remainder = CInt(num  quotient * 1000) num = quotient ' Convert the group into words. result = numbers(remainder) & _ " " & groups(group_num) & ", " & _ result ' Get ready for the next group. group_num += 1 valid = True Loop If txtAmount.Text.Length = 0 Then MessageBox.Show("Please enter an amount.") valid = False End If If num < 0 And num > 9999.99 Then MessageBox.Show("Amount must be greater then 0 and less then $10,000 .") txtAmount.Text = String.Empty valid = False End If If valid = True Then Me.Hide() End If ' Remove the trailing ", ". If result.EndsWith(", ") Then result = result.Substring(0, result.Length  2) End If Return result.Trim() End Function 
#7
 
 
Re: How to convert vb .text to number format
View the above samples but please dont just out right copy it unless it was a share ware thingy. 

Tags: number to text, text to number, vb code, word 2007 
Thread Tools  Search this Thread 

Similar Threads for: "How to convert vb .text to number format"  
Thread  Thread Starter  Forum  Replies  Last Post 
How to convert number to text in excel  Jevin  Software Development  9  17052012 07:42 PM 
How to convert math text PDF format to Kindle readable format  The#Gaelic  Portable Devices  7  23022012 12:09 PM 
How to convert HTML to TEXT format ?  Custidio  Windows Software  5  09022010 02:22 AM 
Convert a text document in PDF format (Mac)  Waffle  Operating Systems  4  03022010 10:33 PM 
How can I convert text data into table format?  Ram Bharose  Windows Software  7  30122009 02:58 PM 