Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get check click to produce msgbox???

Status
Not open for further replies.

r3b00t

Technical User
Aug 13, 2002
45
GB
Hi guys

Im doing a simple program where i have 4 command buttons which are 4 questions, a text box which shows the question when one of the command buttons is pressed, 3 text boxes with three possible answers and finally three check boxes, one next to each answer text box. I want the user to click on a check box next to the answer that they think is correct which will produce a msgbox saying that the answer is right or wrong.
Obviously each question changes with each command button pressed, so i want to know on what object i should put code and how to do it?

Sorry if this makes no sense, its just hard to describe

Thanx for bearing with me guys

r3b00t
 
Add a module level variable and an ENUM:
Option Explicit
Private Enum eSelection
Selection1=1
Selection2=2
Selection3=3
End Enum
Private m_Selection As eSelection

First, on the click event of each command button, change the captions and text of the other controls

Private Sub Command1_Click()
label1.Caption="FirstQuestion Caption"
Text1.Text="FirstQuestion Text"
Check1.Caption = ="FirstQuestion Caption CheckBox1"
Check2.Caption = ="FirstQuestion Caption CheckBox2"
Check3.Caption = ="FirstQuestion Caption CheckBox3"

m_Selection = Selection1
End Sub

Now do the same for the other command buttons, changing the values accordingly, especially the variable m_Selection to Selection1,Selection2, or Selection3 respectively)
When you want to process the answers, just check the value of the variable m_Selection

Private Sub CommandProcess_Click()
Select Case m_Selection
Case Selection1
'Do Something based on this selection
Case Selection2
'Do Something based on this selection
Case Selection3
'Do Something based on this selection
End Select
End Sub

And get yourself a VB book for beginners, or download some examples to help yourself further.
You'll learn alot this way.[thumbsup2] [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 

Forgot to add:

Private Sub Check1_Click()
Select Case m_Selection
Case Selection1
MsgBox "Wrong Answer"
Case Selection2
MsgBox "Wrong Answer"
Case Selection3
MsgBox "Right Answer"
End Select
Private Sub Check2_Click()
Select Case m_Selection
Case Selection1
MsgBox "Right Answer"
Case Selection2
MsgBox "Wrong Answer"
Case Selection3
MsgBox "Right Answer"
End Select

End Sub
[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thanx alot, all sorted.

However, I dont understand the code in the module

Option Explicit
Private Enum eSelection
Selection1=1
Selection2=2
Selection3=3
End Enum
Private m_Selection As eSelection

Could you explain this?

Thanx again

r3b00t
 
Note the last 3 lines of CCLINTs first post! Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top