Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2008 > Visual Basic 2008 Essentials
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Visual Basic 2008 Essentials If you are new to Visual Basic programming with version 2008, this is the place to start your questions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Essentials section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 4th, 2009, 09:05 PM
Registered User
 
Join Date: Nov 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up 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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to pull values from dynamic radiobuttons kwilliams ASP.NET 2.0 Professional 0 November 14th, 2008 11:54 AM
DataBinding with Radiobuttons vgsgowrisankar C# 2005 0 May 8th, 2008 05:15 AM
Using Radiobuttons Andrew.Berry ASP.NET 2.0 Professional 6 April 18th, 2008 10:29 AM
Assigning radiobuttons hydra14 C# 7 June 5th, 2004 12:25 AM



All times are GMT -4. The time now is 07:41 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.