Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Best Programming Practises (VB6)

    Hi all,

    I'm currently evaluating my programming practises and thought i'd get your expert opinion on a few things (based on a large project, say, Word for example):

    Is it best to load everything at the start or load it as the user needs it?
    I've always worked on the basis that the user probably wont be using everything so its better to load it as they need it, but alot of popular programs seem to pre-load everything.

    If a user presses the close button on a form, does that unload all of the programming objects/variables used on it or is it best to set them to null/empty/nothing?

    When a function finishes running, do all the objects remove themselves from memory or does everything need to be destroyed?

    (edit - thought of another) - Is it best to add error handling to every single sub/function (at the least, on error resume next) even if its the simplest of functions that in theory could never go wrong? Just through looking at 3rd party component code and VB examples and "how to's" I've noticed that not every sub has error handling.

    I've had a look around the net and found various opinions for all of these, but it seems dependant on the size of the program, is it just experiences that tells you when to destroy objects and variables are there some actual practises to base it on?

    Any help with the above would be much appreciated. Since I started programming I always seem to be programming to strict deadlines and never seem to get the opportunity to explore exactly what happens if I try all of the options above.

    If anyone cares to add to my list of questions please feel free.

    Regards,
    Phil

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Best Programming Practises (VB6)

    With respect to variables retaining values or continuing to exist, I think there are some differences between my VBA experience and VB. Because the VBA "host" typically remains active after execution of a particular procedure is completed, global variables may retain their values in some scenarios. Obviously if you end a VB program, that should never happen. So you say "VB6" and "Word," and I'm not sure which context people really should address. For complete safety, of course, you should always initialize your variables and clean up your objects. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  3. #3
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Best Programming Practises (VB6)

    Thanks for your reply. Reading it made me think my examples aren't as clear as they should have been.

    Say i've programmed something on the scale of paint shop pro. A user clicks a button to load some kind of wizard. When the wizard loads, I made it declare a load of variables and objects used in the wizards process. When the user completes the wizard and it closes (just the wizard, not the whole app), do all those objects get tidied automatically or does everything need to be destroyed manually?

    Also for a program on that scale, would it be better to load everything first (thus quicker for the user once its loaded) or load it as the user needs it (thus better for the operating system as less memory is used, but slower for the user).

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Best Programming Practises (VB6)

    in vba. global stuff retains values as long as project is open.

  5. #5
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Best Programming Practises (VB6)

    > Also for a program on that scale, would it be better to load everything first (thus quicker for the user once its loaded) or load it as the user needs it (thus better for the operating system as less memory is used, but slower for the user).

    Answering the second bit first, if there are "retained" user settings, e.g. preferences, you'd usually load these at startup by reading just the once from registry or .INI file or equivalent. IMO this would be more efficient than multiple/ staggered reads. I'd envisage initializing program variables (with appropriate scopes) with these values.

    > When the user completes the wizard and it closes (just the wizard, not the whole app), do all those objects get tidied automatically or does everything need to be destroyed manually?

    For this kind of operation, if the temp variables are locally (wizard) scoped then they should be destroyed automatically. If anything needs to be retained from the operation, it should set a "retained" variable (as above) when the wizard closes successfully. Finally, when the program is closed, ALL the retained/ persistent variables should be written back to registry etc. in the one operation.

    Hope I'm barking up the right tree with that.

    Alan

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Best Programming Practises (VB6)

    Unless you encounter and unhandled error break, in which case, all variables, including globals, are cleared of their values, although the variables still exist.
    Charlotte

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Best Programming Practises (VB6)

    actually, it is very bad programming to rely on the system to initialize and.or clear variables.
    One should always do this onesself.

    And make sure that objects get set to Nothing and handles closed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •