mascoloj
asked on
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
txtposition.Text = txtposition.Text.Replace("
txtposition.Text = txtposition.Text.Replace("
Notice that I'm assigning the result back to the Text property of txtPosition?
ASKER
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.
ASKER
txtposition.Text.Replace("
txtposition.Text.Replace("
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.