Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
TitleDim xxx As New Employee
Keywordsquick question answer, quiz answer, answer
Categories
 
The first part of the answer (what the interviewer wants to hear) is that this statement is inefficient. When you allocate a variable As New in Visual Basic 6, the compiler does not immediately allocate the item. Instead every time the variable is referenced the code checks to see whether it is allocated or not. If it is not, the program allocates it then. This means the program doesn't allocate the item until it is actually needed. If the item is never needed, it is never allocated.

Unfortunately it also means the program must check whether the variable has been allocated yet every time it uses the variable. This wastes time. It is faster if you declare the variable without the New keyword and then allocate it yourself like this:

    Dim xxx As Employee

Set xxx = New Employee

The second part of the answer is that xxx is a terrible name for the variable.


WJK had two comments:

I hate employment knowledge tests of obscure facts about programming languages. How many of us use the dim xxx as new employee feature??? Why??? Because it is not the efficient/proper method to begin with. Most of us are taught or learned the "correct way". In actual practice, it is far more important being able to navigate the solution. How to quickly resolve the problem using the resources provided.

I did appreciate the knowledge learned from the question, now what to do with it???? :-) I would like to see these types of questions continued in the VB helper forum. You never know what tiny fact may really be of significant help. I have a VB exam guide filled with these questions. In answering them, it seems to me you are "studying to the test" rather than learning a comprehensive knowledge of the subject. In lieu of passing such a test, an employer should offer alternatives such as writing code to solve an appropriate problem relative to the employment.

Is it really necessary to test if the prospect presents MCSD credentials?


I make no defense of employment tests. I post the Quick Questions because I think it's interesting how much learning you can get out of a few lines of code.

Some people make convincing arguments that these tests are worthwhile for weeding out the really unqualified candidates when you have a very large stack of resumes to examine and, for better or worse, some large companies have standard tests.

Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated