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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

756 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