im a begginer in vb and i start creating a multiple choice game,can you please help me about the option button(source code)please give some examples.please help me.

Well, I know a little bit about it so I'll try to help. You should first create a frame from the toolbox. Then on top of that you can put the option buttons, found in the toolbox, in the frame along with anything else you want in that frame. In this way you can only choose one option within that frame, but you can use other frames where you can choose different options if you want. Does that help any?

thanks but i wanna know what code i use is it a if,else or case?i need some example code

I think it depends more on what you want to do with it. I would probably put the code under a command button. It might say something like this.

If opt1 is true
vb code here
end if
if opt2 is true
vb code here
end if

etc. etc. Why don't you post a little bit more specifically what it is you're trying to do in your application.

Did that help at all or are you still left in the dark? Someone else might be able to help you a little better.

its just like this
example: what animal considered a man,s bestfried?
then i will give a series of answer that you can choose from.
option button1 dog
option button2 cat
option button3 reptile.
all i wanna know is the source code for the option button.
thanks for the time i really appreciate it.

Well you have to give the option buttons names. It depends on what you want the program to use with this information. Like I said, I would probably use a command button under which the code you should put

if opt1 is true then
(whatever you want to happen if this choice is chosen)
end if
if opt2 is true then
(whatever you want to happen if this choice is chosen)
end if
if opt3 is true then
(whateer you want to happen if this choice is chosen)

This code works if you name your option buttons opt1 opt2 and opt3. You can name them what you want. When you click that command button whatever you want to happen depending on which option was chosen should execute. If you want help with that part of the code then tell me what it is you want it to do after the choice has been made.

its just like this
example: what animal considered a man,s bestfried?
then i will give a series of answer that you can choose from.
option button1 dog
option button2 cat
option button3 reptile.
all i wanna know is the source code for the option button.
thanks for the time i really appreciate it.

The answer is dog. So the code must check if the option button for dog is clicked or if the value is true. By the way, how does your app check the answer? Does it have a command button to check or does it check immediately after clicking a choice?

As a beginner it is safe to use a combo box and see whether the code below works for your satisfaction

Private Sub Form_Load()

---------
Combo1.Text="My Animal"
Combo1.AddItem ("Dog")
Combo1.AddItem("Cat")
Combo1.AddItem("You")
combo1.SetFocus
-----------

End Sub

Private Sub Combo1_click()

If Combo1.Text="Dog" then
'do the things for dog here
Else
If Combo1.Text="Cat" then
'do the things for cat
Else
If Combo1.Text="You"
'I think You Got It
Else
'MsgBox "Kindly Select an Animal
go to error handling
Endif
Endif
Endif

End Sub

Or Actually if you want all those options as buttons then you have to see which button is activated.

Private Sub CommandDog_Clicked()
Some code for Dog
End Sub

Private Sub CommandCat_Clicked()
Some code for cat
End Sub

But that's only if he wants something to happen immediately after clicking an option.

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.