RADIOBUTTONS/CHECKBOXES
hi i am new to visual basics and need help on running this example, can some one help me out here thanks.
part 6, the updateSelection? what codes shall i add there, in the example its blank. I have done part 7 and put the part 8 code in the updateSelection procedure. when I run then program the program runs and the form comes up, but when I click the radiobuttons and checkbox, it dont display as anything in the textbox as required in what part 9 says. CAN SOMEONE PLEASE SHOW ME CODE FOR PART B 6) AND WHAT ELSE I NEED TO ADD TO FULLFILL THE REQUIREMENT.
MANY THANKS.
Rrquirements and the names used for the form:
Object Property Setting
Form Text The Selection Program
BackColor Pale yellow
Label Name lblExtras
Text Extras
Font effects Underlined
BackColor Pale yellow
Label Name lblDrink
Text Drink
Font effects Underlined
BackColor Pale yellow
Object Property Setting
Check Box Name chkMilk
Text Milk
Check Box Name chkSugar
Text Sugar
Check Box Name chkBiscuits
Text Biscuits
Radio Button Name radTea
Text Tea
Radio Button Name radHotChocolate
Text Hot Chocolate
Radio Button Name radCoffee
Text Coffee
Text Box Name txtSelection
TextAlign MiddleCentre
BorderStyle FixedSingle
BackColor Pale blue
Text (delete any text in this field)
Button Name btnExit
Text E&xit
BackColor Pale red
Part B Attaching code (code programming)
6 The command button along with each of the option buttons and check boxes need to have instructions (or code) associated with them. These instructions are executed on selection of the object (i.e. event driven). Using the code window enter the instructions given below into each of the procedures. Donât worry if the UpdateSelection() code becomes underlined, this will disappear once you have written the UpdateSelection() procedure later on in this tutorial sheet.
Private Sub radTea_CheckedChanged(â¦â¦.
UpdateSelection()
End Sub
Private Sub radHotChocolate_CheckedChanged(â¦â¦..
UpdateSelection()
End Sub
Private Sub radCoffee_CheckedChanged(â¦â¦â¦
UpdateSelection()
End Sub
Private Sub chkMilk_CheckedChanged(â¦â¦â¦.
UpdateSelection()
End Sub
Private Sub chkSugar_CheckedChanged(â¦â¦.
UpdateSelection()
End Sub
Private Sub chkBiscuits_CheckedChanged(â¦â¦.
UpdateSelection()
End Sub
7. UpdateSelection is a common procedure that is called by all the option buttons and check boxes. This procedure is not associated with any particular object on the form, but any control can access it. To create the procedure, go to the code window and on a blank line just before the End Class statement the following line of code:-
Private Sub UpdateSelection()
When you press the Enter key the code editor will automatically enter the sub-procedure footer (End Sub) for you.
8 Enter into the UpdateSelection() procedure following lines of code:-
Private Sub UpdateSelection()
'Declare all variables in the procedure
Dim Info As String
'Tea
If radTea.Checked = True Then
Info = "Tea"
End If
'Hot Chocolate
If radHotChocolate.Checked = True Then
Info = "Hot Chocolate"
End If
'Coffee
If radCoffee.Checked = True Then
Info = "Coffee"
End If
Info = Info + vbCrLf 'Add a blank line to the list
'Milk
If chkMilk.Checked = True Then
Info = Info + vbCrLf + "Milk"
Else
Info = Info + vbCrLf + "No milk"
End If
'Sugar
If chkSugar.Checked = True Then
Info = Info + vbCrLf + "Sugar"
Else
Info = Info + vbCrLf + "No sugar"
End If
'Biscuits
If chkBiscuits.Checked = True Then
Info = Info + vbCrLf + "Biscuits"
Else
Info = Info + vbCrLf + "No biscuits"
End If
txtSelection.Text = Info
End Sub
9. Run your project and test its operation by trying all the options available. If you cannot see all the information in the text box then stop the program and make the text box a bit bigger on the form.
|