BS4 Input wildcard selection

I’m looking for either more intuitive search or wildcard search of a BS4Input datalist.
eg. User types in ‘Mcdonal’ then the app should display MacDonald,McDonald,Macdonald,Mcdonald etc

Wildcard search could be *onald to get similar results.

You might look at Soundex. The algorithms are easy (but can vary with degree of accuracy desired). No JavaScript libraries I am aware of but can be written in Basic or JavaScript in your AS app. I have some code in an app (under 60 lines of code) but have not tested it lately. I originally used it many years ago in a db application and am considering it again in some web apps. Google it.

I can add that code to this thread, or start a new one for Soundex, after I have tested it. Let me know if that would be of interest.

John

Definitely interested in your code. One of my issues was sheer volume of data. Eg my vet client has nearly 4000 drugs or services in a list. Using a For loop to cycle through could be time consuming vs BS4 datalist filter.

Soundex example to find a misspelling of “atomic” by entering “atmK”.

To make this work for multiple words in a sentence, parse each word in the field being queried and call this function as many times as there are words. This function ignores blanks so you can use them to parse out individual words. I’ll be doing that and will post an update later. ​Call Function Soundex by setting tData and rData in your app. The example is hard coding these for testing purposes.

Dim tData()
Dim rData()

Function Soundex()
  'This function needs to have tData (misspelled search word) and rData (word being searched) set before calling but is hard coded here for this example.
 ​tData = lcase("atmK")  'will be tData
 ​Call TestSoundex()
 ​sData = tData  
 ​tData = lcase("Atomic")  'will be rData
 ​Call TestSoundex()
 ​If tData = sData Then
   ​alert("Got a match")
 ​End If  
End function

Function TestSoundex()
 ​C = tData
 ​tData = Left(C,1)
 ​ln = Len(C)
 ​For kk = 1 To ln
   ​A = Mid(C,kk,1)
   ​If Asc(A) >= 97 And Asc(A) <= 122 Then 'a letter a-z
     ​Select Case A
     ​Case "a", "e", "i", "o", "u", "h", "w", "y"
       ​tData = tData & "0" 
     ​Case "b", "f", "p", "v"
       ​tData = tData & "1"
     ​Case "c", "g", "j", "k", "q", "s", "x", "z"
       ​tData = tData & "2"
      ​Case "d", "t"
       ​tData = tData & "3"  
      ​Case "l"
       ​tData = tData & "4"  
      ​Case "m", "n"
       ​tData = tData & "5"  
      ​Case "r"
       ​tData = tData & "6"  
     ​End Select    
   ​End If  
 ​Next
 ​oData = tData
 ​Do
   ​tData = Replace(tData,"11", "1")
   ​tData = Replace(tData,"22", "2")
   ​tData = Replace(tData,"33", "3")
   ​tData = Replace(tData,"44", "4")
   ​tData = Replace(tData,"55", "5")
   ​tData = Replace(tData,"66", "6")
   ​tData = Replace(tData,"77", "7")
   ​tData = Replace(tData,"88", "8")
   ​tData = Replace(tData,"99", "9")
   ​'tData = Replace(tData,"00", "")
   ​If tData = oData Then Exit Do
   ​oData = tData
 ​Loop 
 ​tData = Replace(tData,"0", "")
 ​tData = Left(tData & "000",4)
End Function

John

That’s very well done. Thanks for sharing. I’ve got the problem of searching through >3000 items. I’m picking there’d be a bit of time to find something in the last element of the array?

You will always have to search through to the last element in the array. That is because the same Soundex code could be generated for different words in your array. You would then have to provide the user with a sub list of choices to select from.

But JavaScript is pretty fast. You’ll need to do some testing to see just how fast.

JavaScript is very fast - run some benchmarks. BTW, BS4 datalist filter is written in JavaScript, so it won’t be faster.

Note: the two Dims are incorrect they are not arrays. The should be:

tData = “”
and rData = “”

John