Results 1 to 5 of 5

Thread: Simple Replace Text In TextBox - Help Needed

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    13

    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.

  2. #2
    Addicted Member Dark Anima's Avatar
    Join Date
    Sep 2008
    Posts
    183

    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?

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    13

    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"

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Simple Replace Text In TextBox - Help Needed

    What kind of application is this?

    Changing existing text into something randem doesn't sound healthy.

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    13

    Re: Simple Replace Text In TextBox - Help Needed

    article rewriter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width