Solved

Please explain the statement...

Posted on 2012-03-14
2
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 81

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 34

Author Closing Comment

by:Mike Eghtebas
ID: 37723425
Thank you
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

717 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