Solved

is there a more accurate way of doing this?

Posted on 2004-09-01
8
170 Views
Last Modified: 2010-05-02
ive tried several ways:


If InStr(LCase(Form1.List1b.list(i2)), LCase(text1x)) Then

If LCase(Form1.List1b.list(i2)) Like "*" & LCase(text1x) & "*" Then

If LCase(message) Like LCase(Form1.List1b.list(i2)) Or LCase(message) Like LCase("*" & Form1.List1b.list(i2)) Or LCase(message) Like LCase("*" & Form1.List1b.list(i2) & "*") Or LCase(message) Like LCase(Form1.List1b.list(i2) & "*") Or LCase(message) = LCase(Form1.List1b.list(i2)) Then

what i am trying to do is search for a text in a message and see if it matches. these work but not the way i was hoping, for example:

the word is "Hi"
and if the message is "Hiland" it triggers because it has "Hi" in highland.  is there a way to search for the Whole word but ignoring the position it is placed?

for example:  Hi! how are you, How are you! Hi, hey Hi how are you? would trigger it.
0
Comment
Question by:andyakira
[X]
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
  • 4
  • 3
8 Comments
 
LVL 10

Expert Comment

by:anv
ID: 11960286
check this code

Private Sub Command1_Click()
Dim str1 As String
str1 = "hi how are you?"
str2 = "highland"
Dim ind!
ind = InStr(1, str2, "hi", vbTextCompare) 'check if hi is found in the string
If ind Then
    If InStr(ind + 1, str2, ",", vbTextCompare) Or InStr(ind + 1, str2, "!", vbTextCompare) Or InStr(ind + 1, str2, " ", vbTextCompare) Then ' if after hi there is any character other than alphabets or numbers but special characters then it mathes the whole word...
        MsgBox "found"
    Else
        MsgBox "not found"
    End If
Else
    MsgBox "not found"
End If
End Sub
0
 

Author Comment

by:andyakira
ID: 11960378
TYVM it works very well, but is there a way to edit this so it accepts just 1 letter after the word? (incase the word is plural) but having this work like it does now with the symbols ;).
0
 
LVL 10

Accepted Solution

by:
anv earned 500 total points
ID: 11960398
for that i wud say u 'll have to maintain a dictionary say a 2-D array that store s the actual word and its plural, then u'll have to campare ur string with that particular array element..

that ways it can work...

but its a long process...

and probably the only way... :))
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:andyakira
ID: 11960422
;]
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 11960477
..for PAQ's sake.. and also so my effort wasn't in vain. ;)

You'd be better off using RegExp for such but there's a longer route for more proper matching.

Form1:
---------
Option Explicit
Private Sub Form_Load()
    Const strSentence As String = "Hi! How are you? Hi, Hello. Hi Bob."
    Const strWord As String = "Hi"
    If FindWord(strSentence, strWord) = True Then
        Call MsgBox("Word found!")
    End If
End Sub
Private Function FindWord(ByVal strSentence As String, ByVal strWord As String) As Boolean
    Dim lngLen1 As Long, lngLen2 As Long
    Dim lngLoop1 As Long, lngLoop2 As Long
    Dim strTemp1 As String, strTemp2 As String
    Dim strIgnore() As String
    Dim blnOk As Boolean
    lngLen1 = Len(strSentence)
    lngLen2 = Len(strWord)
    'just to manage characters allowed after the word.. such as "!", "," and " "...
    strIgnore = Split(",|!| ", "|")
    If lngLen1 > 0 And lngLen2 > 0 Then
        For lngLoop1 = 1 To lngLen1
            If lngLen2 <= (lngLen1 - lngLoop1 + 1) Then
                strTemp1 = Mid(strSentence, lngLoop1, Len(strWord))
                If StrComp(strTemp1, strWord, vbTextCompare) = 0 Then
                    If lngLoop1 = 1 Then
                        blnOk = True
                    Else
                        strTemp2 = Mid(strSentence, lngLoop1 - 1, 1)
                        If strTemp2 = " " Then blnOk = True
                    End If
                    If blnOk = True Then
                        blnOk = False
                        If (lngLen1 - lngLoop1 + 1) > lngLen2 Then
                            For lngLoop2 = LBound(strIgnore) To UBound(strIgnore)
                                If StrComp(strTemp2, strIgnore(lngLoop2), vbTextCompare) = 0 Then
                                    blnOk = True
                                    Exit For
                                End If
                            Next lngLoop2
                        Else
                            blnOk = True
                        End If
                        If blnOk = True Then
                            FindWord = True
                            Exit For
                        End If
                    End If
                End If
            Else
                Exit For
            End If
        Next lngLoop1
    End If
End Function
0
 

Author Comment

by:andyakira
ID: 11963880
wow TYVM zzzzzooc
0
 

Author Comment

by:andyakira
ID: 11969113
if i was to split: !, er, ers, ,.,ed would it look like this?


Split(",|!|s|ed|ers|.| |", "|")
0
 
LVL 10

Expert Comment

by:anv
ID: 11978892
nope u can provide only one delimiter at a time in the split function
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 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…
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

617 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