Solved

Please explain the statement...

Posted on 2012-03-14
2
185 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 78

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

19 Experts available now in Live!

Get 1:1 Help Now