-
Feb 21st, 2017, 11:35 PM
#1
Thread Starter
Junior Member
[RESOLVED] [VB 2015] Is there a way to reset radio buttons?
I'm assigning a radio button that'll have corresponding output in a text box, and then another button to reset my radio buttons. i know the way to typically reset my button selection is:
Code:
Radiobutton1.Checked = false
When I do so it resets the radio button successfully, but when I click on the button again for my output without the radio button selected this time, it still outputs remembering my last radio button selection. I'd like to reset it as if it was never selected so no corresponding radio button output is triggered. So other than what I mentioned above, is there another way to do a hard reset of the radio button?
-
Feb 22nd, 2017, 12:36 AM
#2
Re: [VB 2015] Is there a way to reset radio buttons?
when I click on the button again for my output without the radio button selected this time, it still outputs remembering my last radio button selection.
Then that's the code that's wrong. There's nothing wrong with how you're resetting the RadioButtons. If I had to guess, which I do because you haven't provided the relevant code, I would say that you are setting a variable when a RadioButton is checked and not resetting it when the RadioButton is unchecked, then using that variable when you click that Button. If the variable is the value you're using then obviously you have to reset the variable when you reset the RadioButtons.
-
Feb 22nd, 2017, 12:47 AM
#3
Thread Starter
Junior Member
Re: [VB 2015] Is there a way to reset radio buttons?
Originally Posted by jmcilhinney
Then that's the code that's wrong. There's nothing wrong with how you're resetting the RadioButtons. If I had to guess, which I do because you haven't provided the relevant code, I would say that you are setting a variable when a RadioButton is checked and not resetting it when the RadioButton is unchecked, then using that variable when you click that Button. If the variable is the value you're using then obviously you have to reset the variable when you reset the RadioButtons.
Not sure if I understand what you're saying, when I hit my clear all button i clear all text boxes and radio buttons.
Code:
'Enable indv group box
Private Sub Individual_CheckedChanged(sender As Object, e As EventArgs) Handles Individual.CheckedChanged
Me.GroupBox4.Enabled = Individual.Checked
End Sub
'Enable group group box
Private Sub Group_CheckedChanged(sender As Object, e As EventArgs) Handles Group.CheckedChanged
Me.GroupBox5.Enabled = Group.Checked
End Sub
'Convert group group radio buttons selection to Currency for All
Dim CurrAll As String
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles AddGrpCurrency.CheckedChanged
CurrAll = " [ [GiveAllCurrency "
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles SubtractGrpCurrency.CheckedChanged
CurrAll = " [ [SubtractAll "
End Sub
'Copy all from richtextbox
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Copy.Click
My.Computer.Clipboard.SetText(RichTextBox1.Text)
End Sub
'Clear all forms
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles ClearAll.Click
RichTextBox1.Clear()
RichTextBox2.Clear()
NestTextBox.Clear()
IndvCurrency.Clear()
GrpCurrency.Clear()
AddCurrency.Checked = False
SubtractCurrency.Checked = False
User.Checked = False
RndUser.Checked = False
Individual.Checked = False
Group.Checked = False
NestCheckBox.Checked = False
AddGrpCurrency.Checked = False
SubtractGrpCurrency.Checked = False
txt.Checked = False
exe.Checked = False
url.Checked = False
End Sub
-
Feb 22nd, 2017, 01:14 AM
#4
Re: [VB 2015] Is there a way to reset radio buttons?
Look at this part of your code:
Code:
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles AddGrpCurrency.CheckedChanged
CurrAll = " [ [GiveAllCurrency "
End Sub
What does that code actually do? It sets your CurrAll variable to " [ [GiveAllCurrency " whenever the Checked property changes. Think it through. Is that really what you want to do? No, it's not. Look at this part of your code:
Code:
AddGrpCurrency.Checked = False
If that RadioButton is currently checked and you execute that code, what is going to happen? That is going to change the Checked property of that RadioButton so the first code snippet above is going to set your CurrAll variable to " [ [GiveAllCurrency ", just like you told it too.
Now, what do you ACTUALLY want to? You want to set your CurrAll variable to " [ [GiveAllCurrency " specifically when the Checked property of that RadioButton is set to True. If you only want to do something when the Checked property is True then you need to write your code to do that. I'm not 100% sure but I think that clicking a RadioButton will first raise the CheckedChanged event of the currently checked RadioButton as it is unchecked and then raise the CheckedChanged event of the newly checked RadioButton as it's checked. In that case, you could change the first code snippet to this:
Code:
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles AddGrpCurrency.CheckedChanged
If AddGrpCurrency.Checked Then
CurrAll = " [ [GiveAllCurrency "
Else
CurrAll = Nothing
End If
End Sub
If I'm wrong about the order of events - or even if I'm not - you can simply set the CurrAll variable to Nothing after resetting all the RadioButtons.
-
Feb 22nd, 2017, 01:28 AM
#5
Thread Starter
Junior Member
Re: [VB 2015] Is there a way to reset radio buttons?
Holy crap dude thank you! I just started so I'm making these weird mistakes. You're a genius!
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
|