Results 1 to 6 of 6

Thread: Making VB program more efficient.

  1. #1

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    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

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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.

  3. #3

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Making VB program more efficient.

    Thank you Joacim, looks like i have a lot to change in my existing projects.

    CHeers

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Making VB program more efficient.

    Quote 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.

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Making VB program more efficient.

    Quote 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.

  6. #6

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    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
  •  



Click Here to Expand Forum to Full Width