I have 5 radiobuttons in a set. How can I reset the values of the entire array? RadioSet.Index = -1 doesn’t work. Do I have to pass every button?
Yes. You would need to loop the array (set) and do
RadioBtn(I).value = False
That being said, radio buttons should always have one, and only one, button selected. If you need multiple selections, or no selection, use a checkbox instead.
There are times when you want to force a user to make a choice with radio buttons and it is perfectly acceptable to have no default selected.
[quote=30602:@Roger Clary]Yes. You would need to loop the array (set) and do
RadioBtn(I).value = False
That being said, radio buttons should always have one, and only one, button selected. If you need multiple selections, or no selection, use a checkbox instead.[/quote]
When the screen is presented, the user can make a choice, but there is no default. When the user wants to skip back to this screen (it is part of a workflow), I want to reset the initial choices.
I tried already to do this:
for i as integer = 0 to ubound(buttonSet)
buttonSet(i).value = false
next
that produces an error, so I changed it to:
for i as integer = 0 to 5
buttonSetl(i).value = false
next
Problem is that when the amount of buttons changes I have to maintain this code…
Unfortunately you can’t use Ubound on a Control Set although I wish you could - <https://xojo.com/issue/17627>
Use this code so that you don’t have to maintain the code when you change the number of RadioButtons:
For i As Integer = 0 To Self.ControlCount - 1 // Goes through every control on the window
If Self.Control(i) IsA RadioButton Then // Checks if each control is a RadioButton
RadioButton(control(i)).value = False // Casts each control as a RadioButton to access Value
End If
Next
[quote=30646:@Gavin Smith]Unfortunately you can’t use Ubound on a Control Set although I wish you could - <https://xojo.com/issue/17627>
Use this code so that you don’t have to maintain the code when you changed the number of RadioButtons:
For i As Integer = 0 To Self.ControlCount - 1 // Goes through every control on the window
If Self.Control(i) IsA RadioButton Then // Checks if each control is a RadioButton
RadioButton(control(i)).value = False // Casts each control as a RadioButton to access Value
End If
Next
[/quote]
Thanks Gavin, umm looping through all the controls does not create any memory problems/overhead as this is a Page on a Pagepanel with many, many controls? And… it will reset any Radiobutton it stumbles upon?
It should have a negligible overhead but it would be easy to test.
Yes, it just checks each control and, if it finds Radiobuttons, sets them to false.