Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Please explain the statement...

Posted on 2012-03-14
2
Medium Priority
?
198 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 83

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

609 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