Solved

is there a more accurate way of doing this?

Posted on 2004-09-01
8
165 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
  • 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
 

Author Comment

by:andyakira
ID: 11960422
;]
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
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.
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…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now