Solved

Please explain the statement...

Posted on 2012-03-14
2
188 Views
Last Modified: 2012-03-14
Please demonstrate, add explanation, preferably add some sample codes to illustrate the following statements. I am trying to fully understand the point the author of A, B, and C below is making. Each of these statements most likely true but I am not quite getting them:

A) Never use form or class level variable scope (or access level) unless it is needed.

B) In this code, if the variable strShowMessage is declared as String then that is incorrect since the Messagebox.show does not return String but a DialogResult type:
  If strShowMessage = Windows.Forms.DialogResult.Yes Then

C) “textbook text changed event handler that assigns the textbook content to a local variable” is indeed useless.
0
Comment
Question by:Mike Eghtebas
2 Comments
 
LVL 79

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 37723396
A) Never use form or class level variable scope (or access level) unless it is needed.

These are global variables and as such can be a real pain to debug as you will not know which function or class changed the variable. It also makes it extremely hard to maintain the code as a change in 1 function will affect every other function that uses that variable.

Keeping your variables local to a function and only passing in required variables and only returning another variable then you know exactly where the variable changed and why.

Ergo, never use global variables unless you absolutely have to.

B) strShowMessage is declared as String
Windows.Forms.DialogResult.Yes is an enum not a string,
http://msdn.microsoft.com/en-us/library/system.windows.forms.dialogresult.aspx#Y114

C) “textbook text changed event handler that assigns the textbook content to a local variable” is indeed useless.


when the text changed event handler fires if you simply copy the content to a local variable, then you're going to have the event fire for every change in the textbox. wait for the user to finish entering the data, you can use this to validate data i.e. restrict the data to say numeric or alphabetic characters but it will be firing very often, wait until the user is finished.
0
 
LVL 33

Author Closing Comment

by:Mike Eghtebas
ID: 37723425
Thank you
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now