Oh so that means hes asking to c&p?
im out. school.
Probably, wouldn't surprise me. But either way, you don't have to give him C+P code, clearly however he's having difficulties in getting it to work and I doubt it's because he can't structure the if statements correctly . That's why he made a help thread, to get help. He didn't ask for C+P code.
Originally Posted by NextGen1
Easy is Easy
at most a few lines of code.
The most effective way (easier, you can use a separate form, however, add a Textbox to your tool bar and a button that says find)
Code:
Declare a few things as public ( so you can use them later for replace and find next
'Textbox1 = Find Textbox
'Textbox2 = document
[php]
Public StartPosistion As Integer
Public TargetText As String
[/php]
Create your own function (sub)
[php]
Private Sub Find(ByVal start As Integer)
Dim position As Integer
position = InStr(start, textbox2.Text.ToLower, textbox1.Text.ToLower)
If position > 0 Then
TargetText = position
textbox2.SelectionStart = TargetText - 1
textbox2SelectionLength = Len(TargetText) - (Len(TargetText) - Len(TargetText))
Else
MsgBox("What the ....&*%$")
TargetText = ""
End If
End Sub
[/php]
Now you can search using
[php]
Find(1)
targettext = textbox1.text
[/php]
ah i dont get it xd
well i have one richtextbox( RBox ) and a new form with a textbox. In that new form i got the search button. So wehen i press the search button in want to see the text in RBox be highlighted :S :P
The reason I marked it as a troll post is because you'd only get a shitstorm of C+Pers saying that the code doesn't work.
Keep on topic now.
Okay I was testing NGs out in an attempt to figure out how to fix it for you, but it wasn't working for me (likely my error but oh well) Anyways, I devised a new search function with a little help because I forgot to reset the backcolors
Alrighty, this'll make a nice little selection of each reference if the word you were searching for.
[php]
Private Sub FindMyShit(ByVal WhatToSearch As String)
If RichTextBox1.Text.Length > 0 Then
'basically Im clearing all previous highlighting at the start of each search, so you dont end up with MASS color.'
RichTextBox1.SelectionStart = 0
RichTextBox1.SelectionLength = RichTextBox1.TextLength
RichTextBox1.SelectionBackColor = RichTextBox1.BackColor
Dim document As String = RichTextBox1.Text.ToLower 'we set each of these two variables to lower so that typing "Hello" in the search bar will also highlight "hello".'
Dim WTF As String = WhatToSearch.ToLower 'lol, WTF = What to find, god im hilarious.'
Dim CurrentPos As Integer = 0 'the current position we are searching from.'
Do While document.IndexOf(WTF, CurrentPos) >= 0
CurrentPos = document.IndexOf(WTF, CurrentPos)
RichTextBox1.Select(CurrentPos, WTF.Length)
RichTextBox1.SelectionBackColor = Color.Aqua 'the color of the highlighting'
CurrentPos += WTF.Length 'the next search will start from wherever the last index ended'
Loop
End If
End Sub
[/php]
There you go
j-derry?
do you read books or get teahced at school
or both?
coz ur amazing awesome :O
seriously,i dont know how some1 could know so much
Originally Posted by Devient_
j-derry?
do you read books or get teahced at school
or both?
coz ur amazing awesome :O
seriously,i dont know how some1 could know so much
j-derry?
do you read books or get teahced at school
or both?
coz ur amazing awesome :O
seriously,i dont know how some1 could know so much
J....Derry?
Nah I teach myself
Originally Posted by J-Deezy
Okay I was testing NGs out in an attempt to figure out how to fix it for you, but it wasn't working for me (likely my error but oh well) Anyways, I devised a new search function with a little help because I forgot to reset the backcolors
Alrighty, this'll make a nice little selection of each reference if the word you were searching for.
[php]
Private Sub FindMyShit(ByVal WhatToSearch As String)
If RichTextBox1.Text.Length > 0 Then
'basically Im clearing all previous highlighting at the start of each search, so you dont end up with MASS color.'
RichTextBox1.SelectionStart = 0
RichTextBox1.SelectionLength = RichTextBox1.TextLength
RichTextBox1.SelectionBackColor = RichTextBox1.BackColor
Dim document As String = RichTextBox1.Text.ToLower 'we set each of these two variables to lower so that typing "Hello" in the search bar will also highlight "hello".'
Dim WTF As String = WhatToSearch.ToLower 'lol, WTF = What to find, god im hilarious.'
Dim CurrentPos As Integer = 0 'the current position we are searching from.'
Do While document.IndexOf(WTF, CurrentPos) >= 0
CurrentPos = document.IndexOf(WTF, CurrentPos)
RichTextBox1.Select(CurrentPos, WTF.Length)
RichTextBox1.SelectionBackColor = Color.Aqua 'the color of the highlighting'
CurrentPos += WTF.Length 'the next search will start from wherever the last index ended'
Loop
End If
End Sub
[/php]
There you go
omg im kinda dummy, but i sitll dont get it.
well got my notepad and i added a another form for the search textbox.
In that form (search form) i got i textbox and a button.
so i want to type some text in the textbox then press search and see the highlighet text in my notepad ( richtextbox)
lol im not good at english so i hope u get it xD
Originally Posted by mizzer3
omg im kinda dummy, but i sitll dont get it.
well got my notepad and i added a another form for the search textbox.
In that form (search form) i got i textbox and a button.
so i want to type some text in the textbox then press search and see the highlighet text in my notepad ( richtextbox)
lol im not good at english so i hope u get it xD
Okay, if the search button in form2 and the RichTextBox is in form1, you'll need to tell the program exactly where to look for the richtextbox like this
[php]
Form1.RichTextbox
[/php]
So to modify that code slightly:
[php]
Private Sub FindMyShit(ByVal WhatToSearch As String)
If Form1.RichTextBox1.Text.Length > 0 Then
'basically Im clearing all previous highlighting at the start of each search, so you dont end up with MASS color.'
Form1.RichTextBox1.SelectionStart = 0
Form1.RichTextBox1.SelectionLength = RichTextBox1.TextLength
Form1.RichTextBox1.SelectionBackColor = RichTextBox1.BackColor
Dim document As String = Form1.RichTextBox1.Text.ToLower 'we set each of these two variables to lower so that typing "Hello" in the search bar will also highlight "hello".'
Dim WTF As String = WhatToSearch.ToLower 'lol, WTF = What to find, god im hilarious.'
Dim CurrentPos As Integer = 0 'the current position we are searching from.'
Do While document.IndexOf(WTF, CurrentPos) >= 0
CurrentPos = document.IndexOf(WTF, CurrentPos)
Form1.RichTextBox1.Select(CurrentPos, WTF.Length)
Form1.RichTextBox1.SelectionBackColor = Color.Aqua 'the color of the highlighting'
CurrentPos += WTF.Length 'the next search will start from wherever the last index ended'
Loop
End If
End Sub
[/php]
That should do it. Remember, when interacting between forms you can't just say Button1.Text or something like that, because that will automatically try and find button1 on the current form. First you've got to tell the program that it needs to look on a certain form's controls for that specific button
Hope that helped.
EDIT: Forgot an example.
[php]
Private Sub Button1_click(ByVal Sender As...........) Handles Button1.Click
FindMyShit(TextBox1.Text)
End sub
yeah. but if i try to press the button nothing happens..
i made a private sub and put the code in.
Originally Posted by mizzer3
yeah. but if i try to press the button nothing happens..
i made a private sub and put the code in.
Do you have TeamViewer? I think it'll be a simple fix but I can't really tell you anymore than I already have.
i dont use teamviwer
Use it, ffs.
Originally Posted by Imported
Do you have TeamViewer? I think it'll be a simple fix but I can't really tell you anymore than I already have.