|
-
Jun 26th, 2006, 11:52 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] why does InStr miss?
when looking for a single char, instr seems to miss the occurance if the char occurs as the first or last position in the string.
i have a work around, just repeat the first and last terms in the string, or insert a pad space.
But why is this nessesary?
VB Code:
Public Function InStrW(ByRef LookIn As String, ByRef LookFor As String) As Boolean ' break up lookfor into words, compares each
Dim arWS() As String
Dim xx As Long
Dim match As Boolean
match = True
arWS = Split(Trim(LookFor), " ")
For xx = 0 To UBound(arWS) - 2
If InStr(LookIn, Trim(arWS(xx))) = 0 Then
match = False
Else
Debug.Print "InstrW = True", (arWS(xx)) & "<", Str(xx), arWS(xx) & "<", "instr return: " & Str(InStr(LookIn, Trim(arWS(xx)))), LookIn, vbTab, LookFor
Debug.Print Trim(arWS(xx))
match = True
InStrW = True
xx = UBound(arWS) - 2
Exit For
End If 'term in string?
Next xx
InStrW = match
End Function
(i am subtracting 2 due to the pad space i had to use)
-
Jun 27th, 2006, 12:15 AM
#2
Re: why does InStr miss?
Hrm? I don't see any such problem with InStr:
VB Code:
Dim str As String
str = "ABCDE"
Debug.Print "A:"; InStr(str, "A")
Debug.Print "C:"; InStr(str, "C")
Debug.Print "E:"; InStr(str, "E")
Output:
What is it that your are missing? Can you show the code that doesn't give the result you expect?
-
Jun 27th, 2006, 12:18 AM
#3
Re: why does InStr miss?
 Originally Posted by rnd me
when looking for a single char, instr seems to miss the occurance if the char occurs as the first or last position in the string.
That's not happening to me, example..
VB Code:
MsgBox InStr("testing", "t") 'result: 1
MsgBox InStr("testing", "g") 'result: 7
'(InStrRev starts from the end)
MsgBox InStrRev("testing", "t") 'result: 4
-
Jun 27th, 2006, 01:26 AM
#4
Thread Starter
Hyperactive Member
Re: why does InStr miss?
if (two posts in a row) then call MyError
If InStr(drvList, Left$(LB1.List(xx), 1)) Then LB1.Selected(xx) = True
changed to :
If InStr(1, drvList, Left$(LB1.List(xx), 1), vbTextCompare) Then LB1.Selected(xx) = True
and it works ok. i figured since it was ok for you guys something i was doing was wrong. a little digging on msdn, and i found out that without specifying a compare type, binary is default. binary forces a case-sensitive match, and the string case was the problem.
thank you two for posting! i wasn't sure if i was crazy...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|