|
-
Jul 4th, 2001, 01:54 PM
#1
Thread Starter
Hyperactive Member
find a string...sounds simple!
Dose anyone know any code that will search a text box for a a string of text? I have been experementing with a loop but i havent yet gotten it.
-
Jul 4th, 2001, 02:16 PM
#2
VB Code:
Dim p As Integer
p = InStr(1,Text1.Text, "Hello")
If p <> 0 Then
Text1.SelStart = p
Text1.SelLength = Len("Hello")
Else
MsgBox "Not Found!"
End If
see if that works
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jul 4th, 2001, 02:21 PM
#3
Thread Starter
Hyperactive Member
nope, it is just adding the text at the front of the textbox. Thanks anyway.
-
Jul 4th, 2001, 02:27 PM
#4
VB Code:
Dim p As Integer
p = InStr(1,Text1.Text, "Hello")
If p <> 0 Then
Text1.SetFocus
Text1.SelStart = p-1
Text1.SelLength = Len("Hello")
Else
MsgBox "Not Found!"
End If
this modified version works for me
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jul 4th, 2001, 02:38 PM
#5
-= B u g S l a y e r =-
???
works like a charm for me as well 
peet
-
Jul 4th, 2001, 02:45 PM
#6
-= B u g S l a y e r =-
maby make it a bit more general...
Code:
Private Sub FindString(T As TextBox, sSearchString As String)
Dim p As Integer
p = InStr(1, T.Text, sSearchString)
If p <> 0 Then
T.SetFocus
T.SelStart = p - 1
T.SelLength = Len(sSearchString)
'T.SelText
Else
MsgBox "Not Found!"
End If
End Sub
then :
Code:
Private Sub Command1_Click()
FindString Text1, "test"
End Sub
hope you don't mind me stealing you code crptcblade
peet
-
Jul 4th, 2001, 02:47 PM
#7
Thread Starter
Hyperactive Member
i dont get it then. It places the text at the front of the string, then highlights it. For some reason, it dosent locate it but creates it.
-
Jul 4th, 2001, 02:50 PM
#8
Frenzied Member
check you dont have any code under text1_change() that would mess it up.
retired member. Thanks for everything 
-
Jul 4th, 2001, 02:54 PM
#9
Thread Starter
Hyperactive Member
I think I figured it out. I am using a combo box for my text input. And the textbox I am searching is on another form. Somehow, this is messing it up.
-
Jul 4th, 2001, 02:58 PM
#10
Thread Starter
Hyperactive Member
I also need a nind next. It seems to just find the same one over and over
-
Jul 4th, 2001, 03:01 PM
#11
Thread Starter
Hyperactive Member
fixed it. Thanks, i did have code there, now I need one more thing, how can I make a find next procedure without it jujst finding the same text?
-
Jul 4th, 2001, 03:03 PM
#12
-= B u g S l a y e r =-
eh... so you fixed it... then this isn't needed
-
Jul 4th, 2001, 03:11 PM
#13
-= B u g S l a y e r =-
but this is maybe of interrest :
Code:
Option Explicit
Private iNextStartPos As Integer
Private Function FindString(T As TextBox, sSearchString As String, iStartPos As Integer) As Integer
Dim p As Integer
p = InStr(iStartPos, T.Text, sSearchString)
If p <> 0 Then
T.SetFocus
T.SelStart = p - 1
T.SelLength = Len(sSearchString)
FindString = p + Len(sSearchString)
'T.SelText
Else
FindString = 0
MsgBox "String " & """" & sSearchString & """" & " not found!"
End If
End Function
Private Sub cmdFind_Click()
iNextStartPos = FindString(Text1, "test", iNextStartPos)
If iNextStartPos Then
cmdFind.Caption = "Find next"
Else
cmdFind.Caption = "Find"
iNextStartPos = 1
End If
End Sub
Private Sub Form_Load()
iNextStartPos = 1
End Sub
peet
hmmm... what don't one do in order to increase the post count
-
Jul 4th, 2001, 03:16 PM
#14
Thread Starter
Hyperactive Member
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
|