Multiple String Matching

cable

Access For My Sins
Local time
Today, 23:39
Joined
Mar 11, 2002
Messages
228
Is there a quick way to match a string to a group of strings?

ie
if "xyz" in ("xyz","zzx", "yyx") then true
does that make sense?

it would be even better if I could do like matching ie?
if "xyz" in ("xy*", "xz*") then true

anyone? or do I need to write it?
 
how about

Code:
if instr(1,"xyz,zzx,yyx" ,"xyz",vbTextCompare) then


or if you want wild cards


if "xyz" like "xy?" then

elseif "xyz" like "zz?" then

elseif "xyz" like "yy?" then

end if
 
trouble is I can't make that code user defined or expandable.
 
meaning you dont want the user to be able to define? .... or... the provided solution doesn't let you?


If you don't think the provided solution would let you ... take a look into application.VBE.ActiveCodePane.CodeModule.InsertLines ... or even any activecodepane option.
 
Ended up with this:
Code:
Public Function InSet(sString As String, sSet As String) As Boolean
'see's if sstring is in a set of strings
'set is ; delimited like patterns
Dim sSetItems As Variant
Dim I As Integer

sSetItems = Split97(sSet, ";")
For I = 0 To UBound(sSetItems)
    If sString Like sSetItems(I) Then
        InSet = True
        Exit For
    End If
Next I

End Function

split97 is an access97 version of later vba's split command:
Code:
Public Function Split97(sString As String, sDel As String) As Variant
Dim sLocal() As String
Dim I As Integer
Dim iBnd As Integer

sString = Trim$(sString)

If Right$(sString, 1) <> sDel Then sString = sString & sDel
I = InStr(sString, sDel)

Do Until I = 0
    iBnd = iBnd + 1
    ReDim Preserve sLocal(iBnd)
    sLocal(iBnd - 1) = Trim$(Left$(sString, I - 1))
    sString = Right$(sString, Len(sString) - I)
    I = InStr(sString, sDel)
Loop

ReDim Preserve sLocal(iBnd - 1)
Split97 = sLocal
End Function

this then allows:
? InSet("abc","a;b;c")
False
? InSet("abc","a*;b;c")
True

I can then store the sets in a table that the user can change. etc
Just thought, could I have used a single like statement?
 
so is this thread closed? problem solved?
 
yep its helped me...dunno what happens to closed threads on this board though, the code/thread might be useful to others.
 
I'm not sure about this forum, but on most when a thread is closed, it's not open for further edits. Which basically means, no one can add to, change, or take away any information.

I was just asking for my own personal benefit whether I should keep watching/checking up on it.
 

Users who are viewing this thread

Back
Top Bottom