Reputation: 113
I am building a Tic Tac Toe game and I came across some trouble when I was trying to select the Radio Button that the variable states. Heres my code:
'Level Selection Enum
Public Enum GameDifficulty
optEasy = 0
optMedium = 1
optHard = 2
optTest = 3
End Enum
'Default Level
Public SelectedGameDifficulty As GameDifficulty = GameDifficulty.optTest
What I am trying to do is select the radio button that the variable SelectedGameDifficulty states but I don't know how. The radio buttons are located on the form and the names for the radio buttons are optEasy, optMedium, optHard, and optTest. Can anybody help me?
Upvotes: 0
Views: 111
Reputation: 216293
You could add all of your radio buttons inside a control array and convert the Enum variable to an integer to index the correct RadioButton and check it
Dim controls() as RadioButton = {optEasy, optMedium, optHard, optTest}
controls(CType(SelectedGameDifficulty, Integer)).Checked = True
Of course this scheme works because the RadioButtons are added inside the array in such a way that they have an order matching the integer value of the associated Enum.
Upvotes: 1