Solved

Please explain the statement...

Posted on 2012-03-14
2
190 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 80

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

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

Suggested Solutions

Title # Comments Views Activity
send messages to whatsapp programatically 2 67
Store results in vb.net 3 25
Footer for each row on Gridview 2 33
Generate Numbers in JQuery file 11 66
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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 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