Solved

is there a more accurate way of doing this?

Posted on 2004-09-01
8
166 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LINQ return type for nested group query 6 71
Write data from SQL to CSV file - position 1 52
VBA error replacing data 6 37
Windows 10 start screen issues 9 51
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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

920 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

13 Experts available now in Live!

Get 1:1 Help Now