| | |
text to numbers, numbers to texrt
![]() |
•
•
Join Date: Jun 2004
Posts: 3
Reputation:
Solved Threads: 0
Thanks. I'll try it. I just did and it doesn't work. I am probably asking the wrong question. If the selection is in words, e.g., "ONE" without the quotes, how do I convert it to the number "1" without the quotes? VAL(Selection) does not work. And if the defined term is a number, e.g., "2" without the quotes, how do I convert it to the word, "TWO" without the quotes?
the only way i could think of doin that would be to set up an array full with the word and the number and then jst using the array to convert back and forth other then that i dont think there is a function built in to do what you want. good luck
well if it was there back then im sure there is away you can do it. i didnt relize you where talking about vba sorry. i dont know any of the extra stuff they add into vba really sorry
•
•
Join Date: Jun 2004
Posts: 173
Reputation:
Solved Threads: 9
[vb]
Private Type typLongHandNumber
ones As String
tens As String
End Type
Dim LongHandNumber(9) As typLongHandNumber
Dim LongHandForm(9) As String
Dim teens(10 To 19) As String
Function InitSystem()
LongHandNumber(0).ones = ""
LongHandNumber(0).tens = ""
LongHandNumber(1).ones = "one"
LongHandNumber(1).tens = "{special}"
LongHandNumber(2).ones = "two"
LongHandNumber(2).tens = "twenty"
LongHandNumber(3).ones = "three"
LongHandNumber(3).tens = "thirty"
LongHandNumber(4).ones = "four"
LongHandNumber(4).tens = "forty"
LongHandNumber(5).ones = "five"
LongHandNumber(5).tens = "fifty"
LongHandNumber(6).ones = "six"
LongHandNumber(6).tens = "sixty"
LongHandNumber(7).ones = "seven"
LongHandNumber(7).tens = "seventy"
LongHandNumber(8).ones = "eight"
LongHandNumber(8).tens = "eighty"
LongHandNumber(9).ones = "nine"
LongHandNumber(9).tens = "ninty"
LongHandForm(0) = ""
LongHandForm(1) = "Thousand "
LongHandForm(2) = "Million "
LongHandForm(3) = "Billion "
LongHandForm(4) = "Tillion "
teens(10) = "ten"
teens(11) = "eleven"
teens(12) = "twelve"
teens(13) = "thirteen"
teens(14) = "fourteen"
teens(15) = "fifteen"
teens(16) = "sixteen"
teens(17) = "seventeen"
teens(18) = "eighteen"
teens(19) = "nineteen"
End Function
Function Convert(dblnumber As Double) As String
' for easy of use I will add a place val counter
Dim placectr As Integer
Dim strNumber As String
Dim strNumlen As Integer
Dim getit As Integer
Dim curplace As String
Dim tempform As String
Dim customlen As Integer
Dim isloc As Integer
isloc = 2
customlen = 0
strNumber = Trim(Str(dblnumber))
strNumlen = Len(strNumber)
If strNumlen < 3 Then isloc = 0
For getit = strNumlen - isloc To -1 Step -3
If (strNumlen - getit) < 0 Then customlen = strNumlen - 3
If isloc <> 2 Then customlen = strNumlen
If customlen = 0 Then
curplace = Mid(strNumber, getit, 3)
Else
curplace = Mid(strNumber, 1, customlen)
End If
tempform = GrabLongHand(curplace, placectr) & tempform
If getit <= 2 And strNumlen < 3 Then Exit For
placectr = placectr + 1
Next getit
Convert = tempform
End Function
Function GrabLongHand(digits As String, placeval As Integer) As String
Dim compile As Integer
Dim digitlen As Integer
Dim teen As String
Dim tempform As String
Dim tempbyte As Integer
digitlen = Len(digits)
If digitlen = 2 Then
If Mid(digits, 1, 1) = "1" Then
teen = teens(Val(Mid(digits, 1, 2)))
GrabLongHand = teen & " " & LongHandForm(placeval) & " "
Exit Function
End If
End If
If digitlen = 3 Then
If Mid(digits, 2, 1) = "1" Then
teen = teens(Val(Mid(digits, 2, 2)))
GrabLongHand = LongHandNumber(Val(Mid(digits, 1, 1))).ones & " Hundred " & teen & " " & LongHandForm(placeval) & " "
Exit Function
End If
End If
For compile = digitlen To 1 Step -1
tempbyte = Val(Mid(digits, compile, 1))
If compile = digitlen - 1 Then
tempform = LongHandNumber(tempbyte).tens & " " & tempform
Else
If (compile = 1 And digitlen = 3) Then
tempform = LongHandNumber(tempbyte).ones & " Hundred " & tempform
Else
tempform = LongHandNumber(tempbyte).ones & " " & tempform
End If
End If
Next compile
tempform = tempform & LongHandForm(placeval)
GrabLongHand = tempform
End Function
Private Sub Command1_Click()
Label1.Caption = Convert(Val(Text1.Text))
End Sub
Private Sub Form_Load()
InitSystem
End Sub
[/vb]
Private Type typLongHandNumber
ones As String
tens As String
End Type
Dim LongHandNumber(9) As typLongHandNumber
Dim LongHandForm(9) As String
Dim teens(10 To 19) As String
Function InitSystem()
LongHandNumber(0).ones = ""
LongHandNumber(0).tens = ""
LongHandNumber(1).ones = "one"
LongHandNumber(1).tens = "{special}"
LongHandNumber(2).ones = "two"
LongHandNumber(2).tens = "twenty"
LongHandNumber(3).ones = "three"
LongHandNumber(3).tens = "thirty"
LongHandNumber(4).ones = "four"
LongHandNumber(4).tens = "forty"
LongHandNumber(5).ones = "five"
LongHandNumber(5).tens = "fifty"
LongHandNumber(6).ones = "six"
LongHandNumber(6).tens = "sixty"
LongHandNumber(7).ones = "seven"
LongHandNumber(7).tens = "seventy"
LongHandNumber(8).ones = "eight"
LongHandNumber(8).tens = "eighty"
LongHandNumber(9).ones = "nine"
LongHandNumber(9).tens = "ninty"
LongHandForm(0) = ""
LongHandForm(1) = "Thousand "
LongHandForm(2) = "Million "
LongHandForm(3) = "Billion "
LongHandForm(4) = "Tillion "
teens(10) = "ten"
teens(11) = "eleven"
teens(12) = "twelve"
teens(13) = "thirteen"
teens(14) = "fourteen"
teens(15) = "fifteen"
teens(16) = "sixteen"
teens(17) = "seventeen"
teens(18) = "eighteen"
teens(19) = "nineteen"
End Function
Function Convert(dblnumber As Double) As String
' for easy of use I will add a place val counter
Dim placectr As Integer
Dim strNumber As String
Dim strNumlen As Integer
Dim getit As Integer
Dim curplace As String
Dim tempform As String
Dim customlen As Integer
Dim isloc As Integer
isloc = 2
customlen = 0
strNumber = Trim(Str(dblnumber))
strNumlen = Len(strNumber)
If strNumlen < 3 Then isloc = 0
For getit = strNumlen - isloc To -1 Step -3
If (strNumlen - getit) < 0 Then customlen = strNumlen - 3
If isloc <> 2 Then customlen = strNumlen
If customlen = 0 Then
curplace = Mid(strNumber, getit, 3)
Else
curplace = Mid(strNumber, 1, customlen)
End If
tempform = GrabLongHand(curplace, placectr) & tempform
If getit <= 2 And strNumlen < 3 Then Exit For
placectr = placectr + 1
Next getit
Convert = tempform
End Function
Function GrabLongHand(digits As String, placeval As Integer) As String
Dim compile As Integer
Dim digitlen As Integer
Dim teen As String
Dim tempform As String
Dim tempbyte As Integer
digitlen = Len(digits)
If digitlen = 2 Then
If Mid(digits, 1, 1) = "1" Then
teen = teens(Val(Mid(digits, 1, 2)))
GrabLongHand = teen & " " & LongHandForm(placeval) & " "
Exit Function
End If
End If
If digitlen = 3 Then
If Mid(digits, 2, 1) = "1" Then
teen = teens(Val(Mid(digits, 2, 2)))
GrabLongHand = LongHandNumber(Val(Mid(digits, 1, 1))).ones & " Hundred " & teen & " " & LongHandForm(placeval) & " "
Exit Function
End If
End If
For compile = digitlen To 1 Step -1
tempbyte = Val(Mid(digits, compile, 1))
If compile = digitlen - 1 Then
tempform = LongHandNumber(tempbyte).tens & " " & tempform
Else
If (compile = 1 And digitlen = 3) Then
tempform = LongHandNumber(tempbyte).ones & " Hundred " & tempform
Else
tempform = LongHandNumber(tempbyte).ones & " " & tempform
End If
End If
Next compile
tempform = tempform & LongHandForm(placeval)
GrabLongHand = tempform
End Function
Private Sub Command1_Click()
Label1.Caption = Convert(Val(Text1.Text))
End Sub
Private Sub Form_Load()
InitSystem
End Sub
[/vb]
![]() |
Similar Threads
- Loop counting odd and even numbers (C++)
- Counting Numbers inside text area (Visual Basic 4 / 5 / 6)
- How to validate? please help to me! (JavaScript / DHTML / AJAX)
- Inserting Page Numbers (Java)
- Overlocking Pointless? (Motherboards, CPUs and RAM)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: grabbing source from excel file (was: please, somebody help me!!!)
- Next Thread: Adodc? Data Control?
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





