|
-
Dec 4th, 2009, 05:38 AM
#1
Thread Starter
New Member
Simple Replace Text In TextBox - Help Needed
Here is what i have so far
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim r As New Random
Label1.Text = r.Next(1, 5)
If Label1.Text = "1" Then
RichTextBox1.Text = Replace(RichTextBox1.Text, TextBox1.Text, "resgg")
ElseIf Label1.Text = "2" Then
RichTextBox1.Text = Replace(RichTextBox1.Text, TextBox1.Text, "thnks")
ElseIf Label1.Text = "3" Then
RichTextBox1.Text = Replace(RichTextBox1.Text, TextBox1.Text, "please")
ElseIf Label1.Text = "4" Then
RichTextBox1.Text = Replace(RichTextBox1.Text, TextBox1.Text, "overs")
ElseIf Label1.Text = "5" Then
RichTextBox1.Text = Replace(RichTextBox1.Text, TextBox1.Text, "tester")
End If
At the moment i have to enter text in Textbox1 that i want to replace, and then when i click the button it will replace it with a random entry from the list.
That's great but ideally i want a solution where i can select text in the RichTextBox1 between markers like * or / and replace the chosen text on every button click, not just once.
At the moment it replaces text in the RichTextBox1 only once. I need it to do it every time i click the button.
It is for a content rewriter.
Any help greatly appreciated.
-
Dec 4th, 2009, 05:56 AM
#2
Addicted Member
Re: Simple Replace Text In TextBox - Help Needed
Firstly, your random would never return 5. You'll have to call r.Next(Min, Max + 1) for it to work properly.
Secondly, you might want to use an array to hold the strings, and a variable to hold the number, not a label. Like so:
Code:
Dim R As New System.Random, I As Int32 = R.Next(0, 4 + 1)
Dim Strings() As String = {"resgg", "thnks", "please", "overs", "tester"}
Me.RichTextBox1.Text = Replace(Me.RichTextBox1.Text, Me.TextBox1.Text, Strings(I))
Thirdly.. I'm not quite sure what you're trying to do. What do you mean it does it only once?
-
Dec 4th, 2009, 06:59 AM
#3
Thread Starter
New Member
Re: Simple Replace Text In TextBox - Help Needed
ideally i want to be able to select a piece of text in brackets in the richtextbox, like this..
{this is an} example of text here
and have the text in brackets change to to a random value in the list, every time i click the button.
so on button click one...
"please example of text here"
so on button click two
"thnks example of text here"
-
Dec 4th, 2009, 07:01 AM
#4
Re: Simple Replace Text In TextBox - Help Needed
What kind of application is this? 
Changing existing text into something randem doesn't sound healthy.
-
Dec 4th, 2009, 07:23 AM
#5
Thread Starter
New Member
Re: Simple Replace Text In TextBox - Help Needed
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
|