Hello can anyone please help, I have started the assignments, but am a little confused, what i need is 9 option buttons: at the buttom i have enclosed the code i have written please have a look and please help,

If the user enters option 1, it should make option 4 and option 7 not available

If the user enters option 2, it should make option 5 and option 8 not available, but make rest of the option available

If the user enters option 3, it should make option 6 and option 9 not available, but make rest of the option available

If the user enters option 4, it should make option 1 and option 7 not available, but make rest of the option available

If the user enters option 5, it should make option 2 and option 8 not available, but make rest of the option available

If the user enters option 6, it should make option 3 and option 9 not available, but make rest of the option available

If the user enters option 7, it should make option 1 and option 4 not available, but make rest of the option available

If the user enters option 8, it should make option 2 and option 5 not available, but make rest of the option available

If the user enters option 9, it should make option 3 and option 6 not available, but make rest of the option available

As you can see from my code, I have used the command enable, but it the user presses option 9 it will not allow him to choose option 3 and option 9, but how can I make it work for all of them please help me.

Private Sub Command1_Click()

Dim TEST(5) As String

TEST(1) = "EKMFLGDQVZNTOWYHXUSPAIBRCJ"
TEST(2) = "AJDKSIRUXBLHWTMCQGZNPYFVOE"
TEST(3) = "BDFHJLCPRTXVZNYEIWGAKMUSQO"


If Option1 = True Then
Text1.Text = TEST(1)
Option4.Enabled = False
Option7.Enabled = False

End If

If Option2 = True Then
Text1.Text = TEST(2)
Option5.Enabled = False
Option8.Enabled = False
Else:
Option4.Enabled = True
Option7.Enabled = True
End If

If Option3 = True Then
Text1.Text = TEST(3)
Option6.Enabled = False
Option9.Enabled = False
Else:
Option5.Enabled = True
Option8.Enabled = True
End If


If Option4 = True Then
Text2.Text = TEST(1)
Option1.Enabled = False
Option7.Enabled = False
Else:
Option6.Enabled = True
Option9.Enabled = True
End If

If Option5 = True Then
Text2.Text = TEST(2)
Option2.Enabled = False
Option8.Enabled = False
Else:
Option1.Enabled = True
Option7.Enabled = True
End If


If Option6 = True Then
Text2.Text = TEST(3)
Option3.Enabled = False
Option9.Enabled = False
Else:
Option2.Enabled = True
Option8.Enabled = True
End If

If Option7 = True Then
Text3.Text = TEST(1)
Option1.Enabled = False
Option4.Enabled = False
Else:
Option3.Enabled = True
Option9.Enabled = True
End If

If Option8 = True Then
Text3.Text = TEST(2)
Option2.Enabled = False
Option5.Enabled = False
Else:
Option1.Enabled = True
Option4.Enabled = True
End If

If Option9 = True Then
Text3.Text = TEST(3)
Option3.Enabled = False
Option6.Enabled = False
Else:
Option2.Enabled = True
Option5.Enabled = True
End If

End Sub

One way this could be done is to use a control array on the option buttions with code simmilar to below:

Private Sub Option1_Click(Index As Integer)

    Select Case Index
    
        Case (0)
            Option1(0).Enabled = True
            Option1(1).Enabled = True
            Option1(2).Enabled = True
            Option1(3).Enabled = False
            
        Case (1)
            Option1(0).Enabled = False
            Option1(1).Enabled = True
            Option1(2).Enabled = False
            Option1(3).Enabled = True
            
        Case (3)
            Option1(0).Enabled = True
            Option1(1).Enabled = True
            Option1(2).Enabled = True
            Option1(3).Enabled = True
    
    End Select
    
End Sub

Maybe!!!!
pG

That doesn't do it, because as long as there are ungrouped option buttons, regardless if they are a control array or not, you can only select 1 at a time. The way to make it so that you can have more than 1 option button selected at a time, is to set them up in different groups. You need a Frame control, basically. You put the option buttons of 1 group in a frame, and the option buttons to another group in a different frame, etc, etc. If you want to do it all programmatically, you can put each option button in it's own frame, and make the frame really small or something, and then on_click of each button, have it set all the other buttons to whatever you want them to be....

yes you are right, i spent a few hous understanding it, i used a frame, but my code is still 27 lines, can i used if then else statement,

if option1.enable = true then
option2.enable = false
option3.enable=flase
else
option2.enable = true
option3.enable=true

i can't make it work, is there are simple way, iof so please show me an example please

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.