Solved

is there a more accurate way of doing this?

Posted on 2004-09-01
8
168 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

828 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