Hey guys! Me again.

I want to change some text inside a textbox when a checkbox is checked.

I tried many things, but none seems to work.

I need that, when checkbox gets checked, the textbox value gets deleted from backwars until a dot. Then, place another predefined text immediately after this dot.

If possible, I also want that, before this, the app checks if the textbox is not empty. I think that this might work:

If Caminho.Text = "" Then
'don't do anything
Else
'do the process I described above
End If

Is this right?

Thanks!

I have to tell you the Homer Simpson cracks me up everytime.

Try this.

Add a CheckBox and a TextBox to the form.

Set the TextBox.Text = "Hello.True"

This simulate what you want.

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

        If String.IsNullOrEmpty(TextBox1.Text) Then Exit Sub

        Dim start As Integer = TextBox1.Text.IndexOf(CChar("."))
        If start = -1 Then Exit Sub

        If CheckBox1.Checked Then

            TextBox1.Text = TextBox1.Text.Remove(start, TextBox1.Text.Length - start)
            TextBox1.Text &= ".True"

        Else

            TextBox1.Text = TextBox1.Text.Remove(start, TextBox1.Text.Length - start)
            TextBox1.Text &= ".False"

        End If

    End Sub

I just didn't got the part of:

If CheckBox1.Checked Then

            TextBox1.Text = TextBox1.Text.Remove(start, TextBox1.Text.Length - start)
            TextBox1.Text &= ".True"

        Else

            TextBox1.Text = TextBox1.Text.Remove(start, TextBox1.Text.Length - start)
            TextBox1.Text &= ".False"

        End If

What is the purpose of TextBox1.Text &= ".True"/".False"? The rest seems clear, just this I didn't understand.

Haha, Homer is cool. I love his phrases (:

Thanks!

You said you wanted to change some text when a check box is checked.

Work backwards until a . was found.

That was my interpretation of what you meant.

What is it you want.

I'll test it later, now I'm going to my grandma house. I'll post it here as soon as I can.

Merry Christmas everyone!

It worked the way I thought! Thank you!

Just one thing... I really didn't get what that part I've quoted does. Not exactly what it does, but how it does. Can you give me a little explanation about it?

And how can I implement a small variable to store old textbox value? Before changing the text? This can be useful (:

Another thing that may make things harder (to me): I've created a save file dialog. When the checkbox is active, it only show option to save a *.exe file. But, I can write *any* extension on textbox. Although it will use the stored value of save file dialog, it can lead to misunderstand of what the program will do. How can I restrict extensions that get written in textbox?

I don't know what you mean with the part i quoted. Explain.

Store the old text in the Textbox.tag.

The save file dialog. Is the user allowed to add a "." to the text. If so are they allowed to enter anything other than a exe extension?

Sorry, what the part that I've quoted. My bad.

If CheckBox1.Checked Then

            TextBox1.Text = TextBox1.Text.Remove(start, TextBox1.Text.Length - start)
            TextBox1.Text &= ".True"

        Else

            TextBox1.Text = TextBox1.Text.Remove(start, TextBox1.Text.Length - start)
            TextBox1.Text &= ".False"

        End If

I didn't understand how this works.

Well, lets try explain in other words. User picks a filename with save file dialog. But, the dialog has predefined extensions (in my case, are rar, zip and 7z if the checkbox isn't checked. if it is, the only avaliable extension will be exe). The textbox will show the full path of the file the user selected on save file dialog, with extension. the user can freely change extension, even if the checkbox that limits the extension to exe is checked. I want to restrict it. Example: if the checkbox is checked, te user will not be able to write anything after a dot than exe.

Like: checkbox is checked. i try to write filename.letssaythatthisareaextensionveryverylong. When I finish, it will automatically delete anything until the dot and replace it with exe. thats why I asked it before.

how can I do it?

I'm picken up what your puttin down.

Unfortunatley, Natural Light is my favorite, and more unfortunate I've been installing bud light. Maybe After the children open the presents in the moring I'll put together a sample for you, if no one else has.

Merry Christmas! And Merry Birthday To Me!

Allright (: I'll paciently wait to see if someone else has another light to me :D

Merry christmas and happy birthday :D

Guys, I changed a bit the things. The user will not be able to edit the textbox anymore. It'll just show the path. I decided this to make things easier.

I'll try to implement the text changes by myself, and I'll come back here to show if it worked or no.

As soon as I get it, or not.

thanks for the help in advance, anyway! :D

I've changed more things.

I'm not using 7-zip as compressor anymore, which means that I don't need to change the extensions anymore.

The method shown above worked perfectly, did exactly what I wished. This can be useful for someone in the future, but not to me now (:

I really appreciate the help. I'm learning a lot here and I'll not foget this!
Thanks.

This question has already been answered. Start a new discussion instead.