|
-
Apr 26th, 2000, 01:54 PM
#1
Thread Starter
Lively Member
little help?
I'm trying to create a text search, note that all variables are defined even if they aren't listed here
if i type for example "hi hi hi hi hi" then click search it will find and highlight the first one, then i click it again and it finds the second, then when i click it again it finds the second again any help?
here is the code:
Code:
Dim searched, newsearch As Long
Private Sub cmdSearch_Click()
searchtext = txtSearch.Text
newsearch = searchpos + Len(searchtext)
If searched = 0 Then searchpos = InStr(frmMain.txtNotepad.Text, frmSearch.txtSearch.Text)
If searched = 1 Then searchpos = InStr(newsearch, frmMain.txtNotepad.Text, frmSearch.txtSearch.Text)
If searchpos > 0 Then
frmMain.txtNotepad.SetFocus
searchlen = Len(searchtext)
frmMain.txtNotepad.SelStart = searchpos - 1
frmMain.txtNotepad.SelLength = searchlen
End If
searched = 1
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Select Case UnloadMode
Case vbFormControlMenu
searched = 0
End Select
End Sub
mail me at [email protected] if you need more specifics but can help me
-
Apr 26th, 2000, 02:03 PM
#2
Fanatic Member
Set the instr() 'from' param to textbox.seltext + 1
This way the search will always start from after the current curser position. after a search the curser will move to the found text to a second search can start from there.
If the intention is to be able to move the curser yet continue from the same point then set a public variable to textbox.seltext + 1 after a search and search from there each time.
Put an if statement in at the begining so that the variable is less than 1 or greater than len(text) to avoid errors
-
Apr 26th, 2000, 02:21 PM
#3
PowerPoster
There's also a demo project on my page showing how to find text using InStr and highlighting it... (misc section)
-
Apr 26th, 2000, 02:46 PM
#4
Thread Starter
Lively Member
uh....
I don't think there is a .seltext property for txt boxes.... at least my VB(6.0) doesn't awknowledge it.
It gives me a type mismatch error...?
-
Apr 26th, 2000, 02:47 PM
#5
PowerPoster
As I remember RichTextBoxes have...
-
Apr 26th, 2000, 03:16 PM
#6
Thread Starter
Lively Member
I'm not usin rich text box(at least for now)
I'm not usin rich text box(at least for now)
-
Apr 26th, 2000, 03:21 PM
#7
Addicted Member
I don't think there is a .seltext property for txt boxes.... at least my VB(6.0) doesn't awknowledge it.
Try:-
Code:
With txtNotepad
newsearch = .SelStart + .SelLength + 1
End With
-
Apr 26th, 2000, 03:23 PM
#8
PowerPoster
My demo uses a simple text box...
-
Apr 26th, 2000, 03:46 PM
#9
Thread Starter
Lively Member
Thanks to everyone i finally got it workin how i wanted(more or less )
later,
Iceman
(till my next stupid question anyway )
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
|