|
-
Jul 26th, 2005, 06:24 AM
#1
Thread Starter
Frenzied Member
Making VB program more efficient.
Hello again, i am half way through a few projects. I am keen on making them as efficient and user friendly as possible.
I have some questions about making programs efficient in VB.
1) When do you decide whether to set values of components at run time, or in design?
For example seting the text of a tet box to "Bill" in design, or when the program runs?
2) Where is the best place to declare variables.
I currently have all my varibales in the global module. But would it be easier on the memory if i had variables which were only being used once, in the procedure (locall)
Thank You
ILMV
-
Jul 26th, 2005, 06:57 AM
#2
Re: Making VB program more efficient.
1. Setting the properties at design time is always a good choice if you always will have the same default value when the application starts. If you sometimes need to change that property at start-up there is actually no reason to set it at design time.
2. You should always use the smallest possible scope. Which means that if a variable is only used inside one procedure never declare it outside of that procedure.
-
Jul 26th, 2005, 06:59 AM
#3
Thread Starter
Frenzied Member
Re: Making VB program more efficient.
Thank you Joacim, looks like i have a lot to change in my existing projects. 
CHeers
-
Jul 26th, 2005, 07:03 AM
#4
Re: Making VB program more efficient.
 Originally Posted by I_Love_My_Vans
1) When do you decide whether to set values of components at run time, or in design?
For example seting the text of a tet box to "Bill" in design, or when the program runs?
No real impact on performance, but if you use resource files (multiple language support, etc.) then it makes your EXE file slightly larger to set them all at design time; especially with images, which use a lot of space. You should make sure everything is in the EXE only once, so if you are using a resource file, delete all your design-time property values and you will see a decrease in file size.
2) Where is the best place to declare variables.
I currently have all my varibales in the global module. But would it be easier on the memory if i had variables which were only being used once, in the procedure (locall)
Ignoring the issues of scope, it uses less memory overall to use local variables, but you spend more time allocating them and destroying them when they go in and out of scope. However that's no reason at all to use a larger scope than necessary; that just causes headaches later when you are trying to figure out what the variable does.
-
Jul 26th, 2005, 08:20 AM
#5
Re: Making VB program more efficient.
 Originally Posted by Joacim Andersson
2. You should always use the smallest possible scope. Which means that if a variable is only used inside one procedure never declare it outside of that procedure.
You should make this statement a religion!!!!
I have seen programs where the exact same variable is declared in every single solitary event on every form throughout the project, and I have seen programs where every variable is Public, and many of these used just once. Variable declaration misuse just makes me cringe.
-
Jul 26th, 2005, 08:27 AM
#6
Thread Starter
Frenzied Member
Re: Making VB program more efficient.
Then cringe me up real good. I am ew at programming, you should see some of my work 
ILMV
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|