Search for 2 words at once

Posted on 2002-03-12
Last Modified: 2010-05-02
I currently search for a specific string that is being populated in a textbox. I would like to be able to provide two key words to look for when the serial data is being read. So if one comment is there and one is not it could parse the data and continue.

Here is my search for one word below.


Dim hFind As String
Dim hString As String
Dim hCounter As Long
Dim hSearch As String
hFind = False
Do While hFind = False
hSearch = Mid$(line_command$, 6)
hCounter = InStr(Term.Text, hSearch)

If hCounter Then
 Term.SelStart = hCounter - 1
 Term.SelLength = Len(hSearch)
 Term.SelText = ""
 hFind = True

hSearch = Mid$(line_command$, 6)
hString = hSearch
hCounter = InStr(Term.Text, hSearch)
 Do While hFind = False
    DoEvents    ' Yield to other processes.
Exit Do
End If
  If Timer - lStartTime > 15 Then
    Term.BackColor = &HFF&
    Local_flag = False
    Global_flag = False
    Fail_Command$ = line_command$
    FrmMain.StatusBar.Panels(2).Text = "Verification   Failure trying to verify " + hSearch
 Exit Do
 End If
Question by:smurray3
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 18

Expert Comment

ID: 6858006
if i understand you correctly, you have "search1 search2" in your textbox and you want to search your string for both search1 and search2...

Dim search() as string

search = split(text1.text, " ")

then do something like

for i = 0 to UBound(search)
   '' do your search routine

is that what you want?


Author Comment

ID: 6858036
I currently have just one search routine in that mess of code. I would however like to be able to hardcode a search string. Say if something like "new user" was feed in while I was searching for "Tom" I could process the new user and then the other.
Hope this makes sense
LVL 18

Expert Comment

ID: 6858874
> Hope this makes sense

yeah, not really :(
LVL 75

Accepted Solution

Anthony Perkins earned 250 total points
ID: 6858954
This is trivial with the VBScript Regular Expression library.  Take a look at this link:


Author Comment

ID: 6864747
Thanks, The link helped

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
message box in access 4 55
Copy a row 12 75
VBA: Select SQL query based on a config Sheet v2 11 55
Excel Macro update each line based on another worksheet 2 58
Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question