Rough Search

How can I tell VB to search for only part of a string instead of the whole thing. So if somebody searched for 'da' they would find records 'dan karran', 'dan'

Any help appreciated...
dankarranAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vbWayneCommented:
this should work

Select * from yourtable where yourfield like('*da*')

'Wayne
0
dankarranAuthor Commented:
Ok, how would I integrate that into here:

    Open App.Path & "\contacts.dat" For Random As #1 Len = Len(Contact)
    ContactTotalRec = LOF(1) / Len(Contact)
    ContactCurrentRec = 1
    For i = 1 To ContactTotalRec
    Get #1, i, Contact
    If LCase(Trim$(Contact.ContactName)) = LCase(Trim$(TheString)) Then
        WFind.LResults.AddItem (Contact.ContactName)
        AnyResult = True
    End If
    Next i
    Close #1


NB: Contact is a file, TheString is a variable passed to a subroutine

I want to search through all the records in teh file to find a match (even just a few letters of it) then add it to a listbox
at the moment it only works if the exact same string is entered as TheString (ignoring case as both are converted to lowercase before searching)
0
Éric MoreauSenior .Net ConsultantCommented:
You can't use vbWayne solution since it is not a relational-database source.

So instead, use this (only one line of your own solution is changed):

Open App.Path & "\contacts.dat" For Random As #1 Len = Len(Contact)
ContactTotalRec = LOF(1) / Len(Contact)
ContactCurrentRec = 1
For i = 1 To ContactTotalRec
    Get #1, i, Contact
    'The next line is changed
    If InStr(1, LCase(Trim$(Contact.ContactName)) , LCase(Trim$(TheString)) ) <> 0 Then
        WFind.LResults.AddItem (Contact.ContactName)
        AnyResult = True
    End If
Next i
Close #1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

dankarranAuthor Commented:
Sorry vbWayne, but emoreau's answer was much more helpful.

Maybe I didn't make it clear when I first asked the question.
0
dankarranAuthor Commented:
Thanks emoreau... I've no idea how it works but it solves the problem
:)
0
Éric MoreauSenior .Net ConsultantCommented:
The Instr statements stands for "Inspect String". It returns the first position of the occurence starting at the position stated at the 1st parameter of the search string or substring (3rd paramater) in the source string (2nd parameter).

So if 0 is returned, that means that the substring is not found!
0
vbWayneCommented:
No Problem....I just assumed!
Have a good one.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.