Here are some tips for optimizing your code mainly for speed.
I found some tips by Billy&George Software and Peter Dimitrov, if you want to get some more, search VB Online for "Optimizing for speed", "Optimizing code" and "Optimizing for size".
Take a minute to think over these pieces and you'll find that your code can be made much faster.
Use variables instead of constants
If you are using given constant many times in your code, then why don't you store it in a variable and use the variable later. See the following two extracts of code. The second one executes faster.
'Executes 1
For X = 1 to 10000
A = X * 3.1415927
Next X
'Executes 2
PI = 3.1415927
For X = 1 to 10000
A = X * PI
Next X
Use simpler math operations
Different types of calculation take different time for the computer to process. Thus wherever you can, replace expressions like X * 2 with X + X, A / 10 with A * 0.1 or A^2 with A * A. They really run faster.
Be careful with repeating operations
Sometimes, a certain calculation may be done several times in vain. This could happen in many different ways. I will illustrate it with two simple examples.
'Executes 1
For X = 1 to 1000
For Y = 1 to 100
P = X * 10 + Y
Next Y
Next X
'Executes 2
For X = 1 to 1000
T = X * 10
For Y = 1 to 100
P = T + Y
Next Y
Next X
The second example runs better, because X * 10 is repeated only 1000 times compared to 100000 times in the first one.
Read to Microsoft's article on How to Optimize Size and Speed of Visual Basic Applications
Previous Post
Access to your POP3 mailbox with FreePOP
Access to your POP3 mailbox with FreePOP
Related Posts
MANAGE XPS: Different spheres of project life cycle problem handlerThe software package MANAGE XPS handles problems related to different spheres of project
Software Development and System AnalysisSoftware Development Methodologies and System Analysis Systems Analysis is a detailed stu
Hide program in Ctlr-Alt-Del listIf you press Ctrl-Alt-Del at the same time a listbox will appear and you can see all prog
News from the VB teamThe latest updates and new released you should know from the Visual Basic team, There's y
Key to LCD InterfacingLiquid crystal display is very important device in embedded system. It offers high flexib
Put your VB application into deep sleepThere may be occasions when you want an application to wait for a specified period of tim