0
VB6 Myths
Posted by Erik Gaius,aka [ K i r E ]
on
Tuesday, March 10, 2009, 1:32 PM
in
Tipz n Trix
Warning: Some code shown in this post should NOT be used.
I learned visual basic 6 during my junior year in high school, and it was really fun compared to c++. However, I've found out that visual basic is hell of a lot slower than C, so I searched for ways to improve my application's speed. Some tricks worked, but most didn't. Here's a list of myths I discovered from then till now:
1.) Variables and when to initialize them. This code:
For i = LBound(myArray) To UBound(myArray)
Total = Total + myArray(i)
Next i
Is as fast as this code:
Dim LB As Long, UB As Long
LB = LBound(myArray)
UB = UBound(myArray)
For i = LB To UB
Total = Total + myArray(i)
Next
In fact, when compiled, they look exactly the same. Also, omitting the counter variable at the end of the for..next loop doesn't help anybody (It even reduces the code's readablity)
2.) One-liner Conditional Statements.
If condition Then statementIs as fast as this:
If condition ThenAll the first example did is reduce your code's readability, nothing more.
statement
End If
3.) More one-liners
Dim newObject As New MyClass..is Actually slower than this..
Dim newObject As MyClassdue to 'auto-instatiation' used by the VB6 compiler. Every time you use the one-liner, VB will check if it should be instantiated.
Set newObject = New MyClass
4.) Bang (!) Operator, or the operator used by adodb (database objects) to simplify data access, is actually slower than fleshing the whole code out. Just like the example above, smaller code doesn't mean faster execution time.
I guess that's that for today's tips & tricks! See ya tommorow!
Post a Comment