Click here to Skip to main content
15,914,070 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionCrystal Report and Password Protected Access Database Pin
shoaibnawaz28-Sep-05 10:37
shoaibnawaz28-Sep-05 10:37 
AnswerRe: Crystal Report and Password Protected Access Database Pin
KaptinKrunch28-Sep-05 16:21
KaptinKrunch28-Sep-05 16:21 
QuestionWindow Forms Pin
SoonerFan28-Sep-05 10:31
SoonerFan28-Sep-05 10:31 
AnswerRe: Window Forms Pin
Dave Kreskowiak28-Sep-05 11:20
mveDave Kreskowiak28-Sep-05 11:20 
GeneralRe: Window Forms Pin
SoonerFan28-Sep-05 16:20
SoonerFan28-Sep-05 16:20 
GeneralRe: Window Forms Pin
Steve Pullan28-Sep-05 16:46
Steve Pullan28-Sep-05 16:46 
GeneralRe: Window Forms Pin
Dave Kreskowiak28-Sep-05 17:11
mveDave Kreskowiak28-Sep-05 17:11 
GeneralRe: Window Forms Pin
Steve Pullan28-Sep-05 18:17
Steve Pullan28-Sep-05 18:17 
Dave, This entry from http://www.vb-helper.com/howto_test_dim_as_new_speed.html explains it better than I can, however I have been programming VB this way for ages for the same reasons. Granted that the efficiency gains are questionable especially with the fast processors of today, it is considered (by me) to be a good programming practice to separate the definition and instantiation/initialization of objects. I have not really investigated this with VB.NET and I'm prepared to be corrected if this is no longer the case. Thanks for asking.

From VB Helper:
When you declare a variable Dim X As New ..., Visual Basic doesn't actually initialize the variable until it uses it. Every time you refer to the variable Visual Basic needs to see if the variable has been initialized and initialize it if it hasn't. It essentially does something like this:

If X Is Nothing Then allocate X
Now do what the program says

The idea is Visual Basic cannot really know apriori whether the variable has been allocated yet.

If you declare the variable and initilize it separately, Visual Basic assumes you know what you're doing and that you will allocate the variable before you use it. If you don't, it raises an error.


...Steve
GeneralRe: Window Forms Pin
Dave Kreskowiak29-Sep-05 0:34
mveDave Kreskowiak29-Sep-05 0:34 
QuestionHelp ! Run-time error '2306' Pin
GJCVB28-Sep-05 8:32
GJCVB28-Sep-05 8:32 
AnswerRe: Help ! Run-time error '2306' Pin
Dave Kreskowiak28-Sep-05 8:53
mveDave Kreskowiak28-Sep-05 8:53 
QuestionVB vs. C# Pin
medicenpringles28-Sep-05 7:37
medicenpringles28-Sep-05 7:37 
AnswerRe: VB vs. C# Pin
Dave Kreskowiak28-Sep-05 8:44
mveDave Kreskowiak28-Sep-05 8:44 
AnswerRe: VB vs. C# Pin
Mike Hodnick28-Sep-05 10:14
Mike Hodnick28-Sep-05 10:14 
GeneralRe: VB vs. C# Pin
Dave Kreskowiak28-Sep-05 17:13
mveDave Kreskowiak28-Sep-05 17:13 
GeneralRe: VB vs. C# Pin
rwestgraham28-Sep-05 17:39
rwestgraham28-Sep-05 17:39 
QuestionOpen and close a PDF document Pin
necao28-Sep-05 6:01
necao28-Sep-05 6:01 
AnswerRe: Open and close a PDF document Pin
Dave Kreskowiak28-Sep-05 7:18
mveDave Kreskowiak28-Sep-05 7:18 
QuestionHow to monitor file time stamp for changes Pin
CamToo28-Sep-05 5:59
CamToo28-Sep-05 5:59 
AnswerRe: How to monitor file time stamp for changes Pin
Dave Kreskowiak28-Sep-05 7:00
mveDave Kreskowiak28-Sep-05 7:00 
QuestionMaintaining an inherited VB6 application Pin
StrayGrey28-Sep-05 5:50
StrayGrey28-Sep-05 5:50 
AnswerRe: Maintaining an inherited VB6 application Pin
Dave Kreskowiak28-Sep-05 6:34
mveDave Kreskowiak28-Sep-05 6:34 
GeneralRe: Maintaining an inherited VB6 application Pin
StrayGrey28-Sep-05 6:57
StrayGrey28-Sep-05 6:57 
GeneralRe: Maintaining an inherited VB6 application Pin
Dave Kreskowiak28-Sep-05 7:07
mveDave Kreskowiak28-Sep-05 7:07 
QuestionVB.Net,C# and SQL DB Script Pin
| Muhammad Waqas Butt |28-Sep-05 5:42
professional| Muhammad Waqas Butt |28-Sep-05 5:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.