Replace function help

I have a simple code snippet that I am having some problems with and I think I am just missing something stupid. In my code I want to change a textbox value according to the value of a checkbox. If the checkbox is checked, take the textbox value and put it in parentheses (), if the checkbox is unchecked remove them. My issue is removing them and my code is below. Any help would be great. Currently the result of the code does not remove them. Maybe you can't replace something with nothing?


PROBLEMATIC CODE:
txtposition.Text.Replace("(", "")
txtposition.Text.Replace(")", "")

CODE USAGE:
Dim Checked As Integer
If ckbvisible.Checked = False Then
    txtposition.Text = "(" & txtposition.Text & ")"
    Checked = 0
ElseIf ckbvisible.Checked = True Then
     txtposition.Text.Replace("(", "")
     txtposition.Text.Replace(")", "")
     Checked = 1
End If
mascolojAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bane83Commented:
The Replace function returns a string.  You're calling the function, but not assigning the returned value to anything.

Dim Checked As Integer
If ckbvisible.Checked = False Then
    txtposition.Text = "(" & txtposition.Text & ")"
    Checked = 0
ElseIf ckbvisible.Checked = True Then
     txtposition.Text = txtposition.Text.Replace("(", "")
     txtposition.Text = txtposition.Text.Replace(")", "")
     Checked = 1
End If
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mascolojAuthor Commented:
OK, So working with your comment, I replaced the code with the following (used M for lack of better thought) but it still didn't work. If I read the code I would assume that it would find ')' and replace it with 'M' but it doesn't. Maybe I am just missing the understanding of your comment. Here's the code I used:

txtposition.Text.Replace("(", "M")
txtposition.Text.Replace(")", "M")


Maybe changing my thinking is needed. Instead of replacing the '(' and ')' with a replace function, could I instead remove the '(' and ')' if they exist with nothing another way? I also have to work with the possibility that the user might remove the '(' and ')' manually in which case the code should not find anything to remove.
0
Bane83Commented:
I think maybe you missed my change.  Look carefully at the change I made for the case where ckbVisible.Checked = true:

     txtposition.Text = txtposition.Text.Replace("(", "")
     txtposition.Text = txtposition.Text.Replace(")", "")

Notice that I'm assigning the result back to the Text property of txtPosition?
0
mascolojAuthor Commented:
Your right - I totally missed it. Thanks for pointing it out. I'm closing the question and assigning you the points. Thanks again for my stupid simple mistake! I knew it was simple.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.