Subscript out of range

K

KJ MAN

In the interest of consolidating code, would it not be best to
write some code that will return data based of the value of the soundex match.
for instance, a 100% match first, 90% next 10 % last and so on (not that 10%
actually needs to be returned).

Would that not be better than having two seperate functions performing the
search?
 
R

Rick Rothstein

***!!*** ElseIf c >= 192 And c said:

The word "Then" that appears on the next line all by itself should be on the
end of the line you highlighted... you newsreader wrapped the text because
the entire line (including its leading spaces) got too long (see what it did
to your ***!!*** mark that you put at the end of the line... it did that to
the word "Then" also). Taking away the leading spaces these two lines which
your newsreader is showing you...

ElseIf c >= 192 And c <= 214 Or c >= 216 And c <= 246 Or c = 248
Then

should have actually read this...

ElseIf c >= 192 And c <= 214 Or c >= 216 And c <= 246 Or c = 248 Then

If you make that change, the function's code should run fine.
 
R

Rick Rothstein

The Soundex function does not return a percentage match value, it just
encodes the normal sound certain letters make and then issues an encoded
value for the letters it sees... that is why you put the found word and the
search word both into the function... to see if the sound of their letters
is the same. The exact match has to be handled separately because an exact
match and an almost match (no matter how close to the original word) all get
the same encoded Soundex evaluation and you wanted exact matches to be found
first.
 
K

KJ MAN

Will soundex return a value of
A woman's love

if the search criteria is
A WOMANS LOVE
?
Notice the apostraphe and case differences.
 
R

Rick Rothstein

I am going to sleep soon, so I'll give you a more complete answer later on
today. I would note that the case of the text is immaterial to the Soundex
function; however, I got values I didn't expect from your examples, so I
looked closer at the code. It looks like it works on single words only, and
then only if they don't contain certain characters (like an apostrophe).
This is an artificial set of restrictions which should not require too much
effort to remove. As I said, I'll look at this again after I wake up.
 
K

KJ MAN

Thanks


Rick Rothstein said:
I am going to sleep soon, so I'll give you a more complete answer later on
today. I would note that the case of the text is immaterial to the Soundex
function; however, I got values I didn't expect from your examples, so I
looked closer at the code. It looks like it works on single words only, and
then only if they don't contain certain characters (like an apostrophe).
This is an artificial set of restrictions which should not require too much
effort to remove. As I said, I'll look at this again after I wake up.
 
R

Rick Rothstein

Okay, here is a completely rewritten Soundex function that ignores
non-alphabetic letters completely...

Public Function Soundex(ByVal S As String) As String
Dim X As Long
Const CodeTab = " 123 12 22455 12623 1 2 2"
' abcdefghijklnmopqrstuvwxyz
If Len(S) = 0 Then Exit Function
S = UCase(S)
Soundex = Left(S, 1)
For X = 2 To Len(S)
If Mid(S, X, 1) Like "[A-Z]" Then
Soundex = Soundex & Mid(CodeTab, Asc(Mid(S, X, 1)) - 64, 1)
End If
Next
Soundex = Replace(Soundex, " ", "")
For X = 1 To 6
Do While InStr(Soundex, CStr(X) & CStr(X)) > 0
Soundex = Replace(Soundex, CStr(X) & CStr(X), CStr(X))
Loop
Next
Soundex = Left(Soundex & "0000", 4)
End Function

I don't want you to get the wrong idea about the accuracy of Soundex
functions in general... they are somewhat crude. Usually they are
implemented to give the user a choice of exact, or somewhat near, matches to
a string he/she types in. You may have seen versions of it implemented in
dictionaries where you type in, for example, fotograf and it returns several
possible words it 'thinks' you might have meant with the idea you will scan
the list and select the actual word (photograph) you meant. As for you
question about "A woman's love" and "A WOMANS LOVE", the function will
return the same code value, so you would conclude they are similar. However,
don't get too comfortable with the matches it returns the same code for "A
man is alive" too. I would say the main strength of the function is when it
is used on single words rather than multi-worded phrases or sentences.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top