Solved

is there a more accurate way of doing this?

Posted on 2004-09-01
8
169 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Script Host failed (Access is denied.) error 6 340
How does CurrentUser work? 10 42
Sub or Function is not defined 6 54
Set WorkSheet  not Working 9 52
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

730 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