Wrox Programmer Forums
|
BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer by Rod Stephens; ISBN: 9780470596906
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 20th, 2011, 01:01 PM
Authorized User
 
Join Date: May 2011
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 10 Tryit

I'm sure this is something simple, but I can't seem to find the solution. On the Chapter 10 Tryit, when I enter the action for the if statement to add the name to the the list box, I'm getting an error that says, "NewComedianForm.nametext is inacessible due to its protection level.
 
Old May 21st, 2011, 10:11 AM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

By default in C# a control's variable is declared private so other form's can't access it directly. You can change that by setting it's Modifiers property to public.

Purists argue that you should not do this, that instead you should create a public property to get and set the control's value. In this case you would create a Name property that would get and set NameTextBox.Text.

I don't think it's that big a deal because it's pretty clear how you use a TextBox so code outside the form is less likely to mess it up. So I'd probably just set the Modifier to public and you should be good to go.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
 
Old June 20th, 2011, 05:36 PM
Registered User
 
Join Date: Jun 2011
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Default Same problem with comedianListBox

Even after I changed the modifier to "Public" for the Form1 list box "comedianListBox" . I get an error that it is not recognized. Any more suggestions?
 
Old June 20th, 2011, 08:20 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

"Not recognized" usually means Visual Studio doesn't know that the control exists. Double check your spelling to make sure you have the right name.

Where is the code that's trying to use the control? If it's in Form1, it should be able to see all of the controls in Form1. If it's in the other form, you would need to change the Modifiers property.

If you can't figure it out, you can zip up the project and email it to [email protected] and I'll take a look.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
The Following User Says Thank You to Rod Stephens For This Useful Post:
Doug Snyder (June 23rd, 2011)





Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 10 cinek BOOK: Beginning iOS 4 Application Development 1 May 1st, 2011 10:47 AM
Chapter 10 thepianoguy BOOK: Professional iPhone and iPad Application Development 1 March 31st, 2011 11:29 AM
chapter 10 ex 1 poldeleeuw BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 2 December 23rd, 2010 07:15 AM
Chapter 10, listing 10-10-app kiwibrit BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 2 August 18th, 2009 04:21 AM
Chapter 10 JimSchubert BOOK: Ruby on Rails for Microsoft Developers 1 May 17th, 2009 11:35 PM





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