الثلاثاء، 31 مايو 2011

Extract Numerical Values from Text Strings!



The purpose of this routine is to take a string of text (such as with a textbox) and extract a numerical value from it. let's say that you have a textbox in which people enter dollar amounts.

Many users are likely to enter something such as "$ 4,335.49" and expect calculations to be performed on it. The trouble is, the value of that string is 0 (zero), not 4335.49!
Using the following function, a person would actually be able to enter a string like "$4,335.49" or even "4335.49 dollars" and still have the value returned as 4335.49.
The function shown below
called PurgeNumericInput requires one argument. That argument is a string containing numbers
with or without special characters.Look at the function below.
Function PurgeNumericInput (StringVal As Variant) As Variant
    On Local Error Resume Next
    Dim x As Integer
    Dim WorkString As String
    
    If Len(Trim(StringVal)) = 0 Then Exit Function ' this is an empty string
    For x = 1 To Len(StringVal)
        Select Case Mid(StringVal, x, 1)
            Case "0" To "9", "."  'Is this character a number or decimal?
                WorkString = WorkString + Mid(StringVal, x, 1)  ' Add it to the string being built
        End Select
    Next x
    PurgeNumericInput = WorkString  'Return the purged string (containing only numbers and decimals
End Function
You then just need to call the function passing a string argument to it. An example is shown below.
Sub Command1_Click
    Dim NewString as Variant
    NewString = PurgeNumericInput("$44Embedded letters and spaces 33 a few more pieces of garbage .9")
    If Val(NewString) <>0 Then
        MsgBox "The Value is: " & NewString
    Else
        MsgBox "The Value is ZERO or non-numeric"
    End If
End Sub
Notice how much alphanumeric garbage was placed in the string argument. However, the returned value should be 4433.9! Two questions might arise when using this type of example.
#1 - What if the string was "0"? This could be determined by checking the length of the string (variant) returned. If the user entered a "0" then the length of the string would be > 0.
#2 - What if the string contains more than one decimal? You could use INSTR to test for the number of decimals. However, chances are, if the user entered more than one decimal you might better have them re-enter that field again anyway.

Speech Recognition Software Finally Works


Surprisingly, the summer of 2007 will be remembered for something other than Paris Hilton’s incarceration: It’s also the 10th anniversary of continuous speech recognition (SR) technology for the PC. Dragon NaturallySpeaking 1.0 came out in the summer of 1997, and those who wanted to dictate to their computers no longer had to pause … between … words.
Originally, the user had to “train” the software for about 45 minutes by reading it a canned test, and the resulting accuracy of about 75 percent meant you couldn’t finish a short sentence

without several glaring errors. Today, having changed hands twice before arriving at version 9.5, training takes only minutes and out-of-the-box accuracy is about 95 percent, meaning you can expect one error per run-on sentence. Dragon’s current vendor, Nuance Communications Inc. of Burlington, MA, reports that sales are booming.
Chris Strammiello, a spokesman for Dragon’s current vendor, Nuance Communications Inc. of Burlington, MA, told LiveScience that Dragon did not catch on with the mass market until Version 8.0 came out in June 2004, offering enough accuracy (thanks to improved algorithms and faster computers) to be truly useful. Sales have been increasing by 30 percent per year since then, he said. (Strammiello would not break out Dragon’s contribution to Nuance’s bottom line, but the firm’s gross sales rose from $130.9 million in 2004, to $232.4 million in 2005, to $388.5 in 2006.)
Up from 95 percent
Actually, my extensive personal use shows that 95 percent is about as accurate as typing, with the software’s chief advantage being that it can keep up with a conversational speed of 140 words per minute, which is easily three times faster than most people can type.
Proofreading is a strange experience, since you are seeing the text for the first time, and you can be confused between what you meant to say, what you really said, and what the computer heard. Long words are almost invariably correct, while short words sometimes seem interchangeable.

Getting to 99 percent accuracy is possible in several weeks using the software’s correction facilities, by which it gradually adjusts itself to your voice. But speaking clearly and consistently is all-important. The personal version of Dragon retails for about $200, while the professional version costs about $765.

Painful decade

Over the past decade and earlier, the history of SR has not been a continuous series of triumphs, as the technology was nearly sunk twice by rampant hucksterism. One of the pioneers in the SR field was Kurzweill Applied Intelligence, two of whose executives were sentenced to prison in 1993 for inventing sales. The remains of that firm were bought in 1997 by a Belgium-based SR firm, Lernout and Hauspie (L&H), which was then reporting steady sales growth.

Dragon’s original vendor, Dragon Systems, was not reporting much growth after releasing NaturallySpeaking in 1997, and in 2000 L&H stepped forward and bought the struggling firm in a stock deal. A few months later, L&H’s sales growth was exposed as fakery, and it collapsed.

ScanSoft Inc. bought the Dragon SR technology at a bankruptcy auction in late 2001 and has continued development through three upgrades since then, meanwhile changing its name to Nuance Communications.



SR elsewhere
SR facilities are also included in Microsoft Office XP, although the fact is apparently not known to most users. Industry observers considered it a test version, as it required a mouse for navigation and correction, unlike Dragon.
Microsoft Vista has an enhanced version of SR that, like Dragon, does not need a mouse.
IBM ViaVoice was also once a competitor of Dragon, but IBM has licensed the software to Nuance, which uses it as an entry-level product. No other large-vocabulary desktop SR products are being marketed in the United States.