Quick Search for:  in language:    
D640,Converts,name,word,string,four,digit,cod
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Visual Basic Stats

 Code: 3,011,557. lines
 Jobs: 115. postings

 How to support the site

 
Sponsored by:

 

You are in:

 
Login



Latest Code Ticker for Visual Basic.
Files Comperator (the right way)
By Jarry Claessen on 6/30


Simple UDP example
By Mick Walton on 6/30


CAPS Trigger
By Trevor Burley on 6/30


Auto clip picture
By Kenneth. Jakobsen on 6/30


Click here to see a screenshot of this code!Game of life clone (cool math)
By Johannes B on 6/30

(Screen Shot)

String to CHR()
By Nikhil Raj on 6/30


Encryption Decryption Demo
By Nikhil Raj on 6/30


Click here to see a screenshot of this code!Serial Registration
By Christian (eXonite Team) on 6/30

(Screen Shot)

AniViewer
By Jerrame Hertz on 6/30


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

ConvertToSoundex

Print
Email
 

Submitted on: 9/22/1998
By: Darrell Sparti 
Level: Not Given
User Rating: By 104 Users
Compatibility:VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0, VB Script

Users have accessed this code 13172 times.
 

(About the author)
 
     Converts a name or word string to a four digit code following Soundex rules. Similar code is used by geniological groups and the US Census Bureau for looking up names by phonetic sound. For example, the name Darrell can be spelled many different ways. Regardles of how you spell it, (Daryl, Derrel, Darel, etc.) the Soundex code is always D640. Therefore, you assign a field in your database to the Soundex code and then query the database using the code, all instances of Darrell regarless of spelling will be returned. Refer to the code comment section for more information.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

'**************************************
' Name: ConvertToSoundex
' Description:Converts a name or word st
'     ring to a four digit code following Soun
'     dex rules.
Similar code is used by geniological groups and the US Census Bureau For
looking up names by phonetic sound. For example, the name Darrell can
be spelled many different ways. Regardles of how you spell it, (Daryl, Derrel,
Darel, etc.) the Soundex code is always D640. Therefore, you assign a field
In your database To the Soundex code and Then query the database using
the code, all instances of Darrell regarless of spelling will be returned. Refer
To the code comment section For more information.
' By: Darrell Sparti
'
' Inputs:A single name or word string.
'
' Returns:A four digit alphanumeric Soun
'     dex code.
'
' Side Effects:This code has not been co
'     mmercially tested.
'
'This code is copyrighted and has' limited warranties.Please see http://w
'     ww.Planet-Source-Code.com/vb/scripts/Sho
'     wCode.asp?txtCodeId=1061&lngWId;=1'for details.'**************************************

'***************************************
'     ********************************
'Function Name:ConvertToSoundex
'Argument:A single name or word string
'Return value:A 4 character code based o
'     n Soundex rules
'Author:Darrell Sparti
'EMail:dsparti@allwest.net
'Date: 9-20-98
'Description:All Soundex codes have 4 al
'     phanumeric
' characters, no more and no less, regar
'     dless
' of the length of the string. The first
'     
' character is a letter and the other 3 
'     are
' numbers. The first letter of the strin
'     g is
' the first letter of the Soundex code. 
'     The
' 3 digits are defined sequentially from
'     the
' string using the following key:
' 1 = bpfv
' 2 = cskgjqxz
' 3 = dt
' 4 = l
' 5 = mn
' 6 = r
' No Code = aehiouyw
' If the end of the string is reached be

'     fore
    ' filling in 3 numbers, 0's complete the
    '     code.
    ' Example: Swartz= S632
    ' Example: Darrell= D640
    ' Example: Schultz = S432
    'NOTE:I have noticed some errors in othe
    '     r versions
    'of soundex code. Most noticably is the
    'fact that not only must the code ignore
    '     
    'the second letter in repeating letters
    '(ll,rr,tt,etc. for example), it must al
    '     so
    'ignore letters next to one another with
    '     the
    'same soundex code (s and c for example)
    '     .
    'Other wise, in the example above, Schul
    '     tz
    'would return a value of S243 which is
    'incorrect.
    '***************************************
    '     *****************************
    Option Explicit
Public Function ConvertToSoundex(sInString As String) As String

Dim sSoundexCode As String Dim sCurrentCharacter As String Dim sPreviousCharacter As String Dim iCharacterCount As Integer 'Convert the string to upper case letter ' s and remove spaces sInString = UCase$(Trim(sInString)) 'The soundex code will start with the fi ' rst character _ of the String sSoundexCode = Left(sInString, 1) 'Check the other characters starting at ' the second character iCharacterCount = 2 'Continue the conversion until the sound ' ex code is 4 _ characters Long regarless of the length of the String Do While Not Len(sSoundexCode) = 4 'If the previous character has the same ' soundex code as _ current character or the previous character is the same _ as the current character, ignor it and move onto the Next sCurrentCharacter = Mid$(sInString, iCharacterCount, 1) sPreviousCharacter = Mid$(sInString, iCharacterCount - 1, 1) If sCurrentCharacter = sPreviousCharacter Then iCharacterCount = iCharacterCount + 1 ElseIf InStr("BFPV", sCurrentCharacter) Then If InStr("BFPV", sPreviousCharacter) Then iCharacterCount = iCharacterCount + 1 End If
ElseIf InStr("CGJKQSXZ", sCurrentCharacter) Then If InStr("CGJKQSXZ", sPreviousCharacter) Then iCharacterCount = iCharacterCount + 1 End If
ElseIf InStr("DT", sCurrentCharacter) Then If InStr("DT", sPreviousCharacter) Then iCharacterCount = iCharacterCount + 1 End If
ElseIf InStr("MN", sCurrentCharacter) Then If InStr("MN", sPreviousCharacter) Then iCharacterCount = iCharacterCount + 1 End If
Else End If
'If the end of the string is reached bef ' ore there are 4 _ characters In the soundex code, add 0 until there are _ a total of 4 characters In the code If iCharacterCount > Len(sInString) Then sSoundexCode = sSoundexCode & "0" 'Otherwise, concatenate a number to the ' soundex code _ base On soundex rules Else sCurrentCharacter = Mid$(sInString, iCharacterCount, 1) If InStr("BFPV", sCurrentCharacter) Then sSoundexCode = sSoundexCode & "1" ElseIf InStr("CGJKQSXZ", sCurrentCharacter) Then sSoundexCode = sSoundexCode & "2" ElseIf InStr("DT", sCurrentCharacter) Then sSoundexCode = sSoundexCode & "3" ElseIf InStr("L", sCurrentCharacter) Then sSoundexCode = sSoundexCode & "4" ElseIf InStr("MN", sCurrentCharacter) Then sSoundexCode = sSoundexCode & "5" ElseIf InStr("R", sCurrentCharacter) Then sSoundexCode = sSoundexCode & "6" Else End If
End If
'Check the next letter iCharacterCount = iCharacterCount + 1 Loop
'Return the soundex code for the string ConvertToSoundex = sSoundexCode End Function


Other 1 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
8/1/1999 6:09:00 AM:Dmitry A. Kirsanov
Cool! Thanks for a great code, right 
what I've been searching for :)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/1/1999 8:09:00 AM:anti
...
this...is
...the 
coolest...
thing i've...
ever seen...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/1/1999 8:12:00 AM:anti
A534 L220 T200 C300 ¦300
anti likes 
this code ¦D
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/3/1999 3:33:00 PM:mark
excellent academic algorithm and one 
that anyone who manages a database of 
many names will adore!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/21/1999 6:18:00 AM:chaolemchai
i want example program with mutimedia 
by visual basic 
i want name of web 
for dowloads example program visual 
basic .
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/23/1999 12:39:00 AM:BigEd
Optimized code that does the same 
thing.  "PadZeros" is for SQL's 
"Like"
Public Function 
ConvertToSoundex(ByVal Word As String, 
Optional PadZeros As Boolean = True) As 
String
Dim NumericVals As String * 
26
Dim lp As Long
Dim char As String 
* 1
Dim charVal As Integer
Dim 
ThisCode As String * 1
Dim PrevCode As 
String * 1
Dim Sdx As String
Word = 
Trim$(UCase$(Word))
!values for each 
letter A to 
Z
NumericVals="012301200224550126230102
02"
Sdx = Left$(Word, 1)
PrevCode = 
""
lp = 2
Do While lp<=Len(Word)And 
Len(Sdx)<=4
char = Mid$(Word, lp, 1)   
             charVal = Asc(char) 
-64
If charVal>=1 And charVal<=26 
Then
ThisCode = 
Mid$(NumericVals,charVal,1)
If 
ThisCode<>PrevCode And ThisCode<>"0" 
Then
Sdx = Sdx & ThisCode
PrevCode = 
ThisCode
End If
End If
lp = lp + 
1
Loop
If PadZeros Then Sdx=Left$(Sdx 
&"0000",4)
ConvertToSoundex = Sdx
End 
Function
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/24/1999 4:10:00 PM:Darrell Sparti
To BigEd:  Though your algorythm seems 
optimized, it is incorrect. Your 
algorythm does the same thing that 
inspired me to write my own.  For 
instance, S and C have the same soundex 
code.  If you had a name like Schwartz, 
the Sch are one code not 2. I spent a 
lot of time researching soundex rules 
and algorythms before I wrote this one. 
 Perhaps there are ways to optimize it 
but they would have to work and give 
you the same code as this one to be 
called Soundex.  So if you choose to 
optimize my code, be sure it returns 
the correct values.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/4/2000 12:35:34 AM:BigEd
My code is correct as is yours.
SCH is 
taken care of properly since S = C 
(both 2) and H=zero with the following 
line--
ThisCode<>PrevCode And 
ThisCode<>"0"
It's funny 
that
http://www.vb2themax.com/Item.asp?
PageID=CodeBank&ID=158
 (02/26/2000) 
uses the same syntax as mine.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/4/2000 1:24:18 AM:BigEd
I stand corrected -- I see MY error.  I 
don't look at the S since it is 
automatically assign BEFORE the 
loop.
Changing MY code 
from:
PrevCode = 
""
TO:
PrevCode=Mid$(NumericVals,Asc(L
eft$(word,1))-64,1)
fixed it, 
thanks.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Visual Basic Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.