pls any one can help making a simple converter from text to numeric converter,
like if i input, one hundred three it will display it in numeric...

All 9 Replies

Uh...we don't really do that sort of thing here. We're more about "If you're stuck, show us what you've done and we'll help you get un-stuck". If you're looking for sample code, you might try a google search first.

Good luck to you anyway!

commented: I like the way you phrased this! +17

What is the largest number you need to convert?

Will you also need to convert fractional numbers?

Or, Decimal Numbers like Ten Point Four?

What are the variant in input text?

Will you accept the above entry as well as Ten dot 4?

Or, One Hundred and 4 vs One Hundred 4?

I did this once back when I was writing childrens programs in QuickBasic but I don't have that code here at work.

It' really not that hard once you properly define the problem. :)

You mean "One hundred three" >> "103" ??
You can start by splitting the text string into segments, and work with them one by one using If.. Then.. statements.

I'll work on some code tonight, if, time allows.

This seems simple, at first, but as you consider all the ways numbers can be written out you quickly realize that the basic Select case statement isn't going to do the job.

That is why some agreement has to be made as to range and whether 41 has to be written as forty-one or fortyone or forty one... The first is the "accepted" method per http://www.merriam-webster.com/mw/table/number.htm

But, your users could make up their own rules...

Basically right now I am looking at around four Select Case sets...

1 through 19 with prefixes for 20 to 90 (the 20-90 would allbe one statement that would call to the next case section - a total of twenty cases)

another one to differentiate between the 20 to 90 prefixes (eight cases)

then 1 through 9 to add to the prefix value (nine casses)

and lastly the modifier... depending upon range hundred, thousand, million would be three cases...

Ie, if you have one (value equals 1) followed by hundred then you would take the 1 and multiply by 100...

smm

OK, here is some working code to convert a String Number into a Value.

One Hundred Three Thousand --> 103000

It is written for non-fractional numbers...

You'll have to change all your numbers to Double and add a whole extra section for after the Point/Dot to handle fractions.

I expect that you will have some debugging to do. :) (It'll be good for you...)

I didn't really have time to extensively debug it myself.

You may also want to add some error checking in the Case Else's or some traps for mis-spelled words, etc.

Also, it expects compond numbers, like 53, to be hyphenated...

As this is my first pass after many many years, I expect that there are some areas that can be cleaned up...

Feel free... :)

AS you read through the code you'll realize that it is on a (test) form with only a textbox and a label.

There is also no code to handle when you do a number line "One Hundred Five Million Two Hundred Fifty Thousand". You'll have to add code to "see" when your Multiplier is les than it was previously. pMultiplier was supposed to do that. But, ran out of time.

``````Option Explicit

Public fValue As Long
Public pMultiplier As Long

Private Sub Text1_KeyPress(KeyAscii As Integer)
fValue = 0
If KeyAscii = 13 Then Label1.Caption = StringToNum(Text1.Text)
End Sub

Function StringToNum(uIn As String) As Long
' Do !NOT! make uIn Public or Global!
Dim StartAt As Long
Dim StoppedAt As Long
Dim RetStr As String
Dim xStr As String
Dim uInp As String

StartAt = 1
RetStr = " "
pMultiplier = 0

Do
' These are all passed by reference as the default
xStr = Scan_To(uIn, StartAt, StoppedAt, RetStr)
uInp = ""
If RetStr <> " " Then
StartAt = StoppedAt + 1
RetStr = " "
uInp = Scan_To(uIn, StartAt, StoppedAt, RetStr)
End If
If Multiplier(xStr) = 0 Then
fValue = fValue + LeadNum(xStr, uInp)
Else
fValue = fValue * Multiplier(xStr)
End If
StartAt = StoppedAt + 1
Loop Until StartAt > Len(uIn)

StringToNum = fValue
End Function

Function LeadNum(uIn As String, Optional uInp As String = "") As Long
Select Case UCase(uIn)
Case "ONE"
Case "TWO"
Case "THREE"
Case "FOUR"
Case "FIVE"
Case "SIX"
Case "SEVEN"
Case "EIGHT"
Case "NINE"
Case "TEN"
Case "ELEVEN"
Case "TWELEVE"
Case "THIRTEEN"
Case "FOURTEEN"
Case "FIFTEEN"
Case "SIXTEEN"
Case "SEVENTEEN"
Case "EIGHTEEN"
Case "NINETEEN"
Case "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"
Case Else
'need to check for Modifier Word
End Select
End Function

Function CompoundNum(uIn, uInp As String) As Long
CompoundNum = 0
Select Case UCase(uIn)
Case "TWENTY"
CompoundNum = 20
Case "THIRTY"
CompoundNum = 30
Case "FORTY"
CompoundNum = 40
Case "FIFTY"
CompoundNum = 50
Case "SIXTY"
CompoundNum = 60
Case "SEVENTY"
CompoundNum = 70
Case "EIGHTY"
CompoundNum = 80
Case "NINETY"
CompoundNum = 90
End Select
End Function
Select Case UCase(uInp)
Case "ONE"
Case "TWO"
Case "THREE"
Case "FOUR"
Case "FIVE"
Case "SIX"
Case "SEVEN"
Case "EIGHT"
Case "NINE"
End Select
End Function

Function Multiplier(uIn As String) As Long
Dim x As Long

Multiplier = 0
Select Case UCase(uIn)
Case "HUNDRED"
Multiplier = 100
Case "THOUSAND"
Multiplier = 1000#
Case "MILLION"
Multiplier = 1000000#
Case "BILLION"
Multiplier = 1000000000#
Case "TRILLION"
Multiplier = 1000000000000#
Case Else
Debug.Print uIn & " has no match"
End Select
x = Multiplier
Debug.Print "Multiplier: " & x
End Function

Function Scan_To(uIn As String, StartAt As Long, StoppedAt As Long, RetStr As String) As String
'This Function Scans a Text String for a Specific sub-String
Dim xStr As String
Dim n As Long

For n = StartAt To (Len(uIn) - Len(RetStr)) + 1
If Mid(uIn, n, Len(RetStr)) = RetStr Then Scan_To = xStr: StoppedAt = n: Exit Function
If Mid(uIn, n, Len(RetStr)) = "-" Then
RetStr = "-"
Scan_To = xStr: StoppedAt = n: Exit Function
End If
xStr = xStr & Mid(uIn, n, 1)
Next n
StoppedAt = n - 1
Scan_To = xStr
End Function``````

I have to wonder whether it is worth posting "possible" solutions or not as I have not gotten any feed back on my posts???

This is what happens when you supply the code to someone without him showing any effort at all. Forget of feedback, i seriously doubt if that guy remembers this thread and is ever going to return back read to your answer.

I have to wonder whether it is worth posting "possible" solutions or not as I have not gotten any feed back on my posts???

Aw sori sir^^ im currently working the codes that you make for me ^^...