Results 1 to 8 of 8
  1. #1
    JustCallMeAl
    Guest

    SAMs Learn...21 days.

    The other day, I decided to purchase a couple of VBA books, particularly because they looked very comprehensive AND they were less than $50/book.

    One that I purchased is Sams Teach Yourself Visual Basic for Applications 5. Very nice book.

    I have already learned a lot about the different functions of the VB Editor that I didn't know before. I do, however, have a question or two.

    1. What is the "Design Mode"? The explanation in the book isn't all that clear, and the Helps file isn't either. When you select Run, Design Mode (or click on the toolbar button), what difference does it actually make?

    2. I noticed Run, Reset. I would like to set up a scenario, to see if Reset does what I hope/think it will. I am working on a form. I have not used a Set frmForm = Nothing in the code, so when I test it multiple times, it can retain information in the text boxes that were typed from a previous iteration. Many times, I will just run the Set... line typed above in the Intermediate Window and all is OK. Would Reset do the same thing?

    Ok, just two for now. Thanks.

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: SAMs Learn...21 days.

    Hi Al,

    1. VBA is always in design mode (unlike VB, I gather), so this doesn't have a lot of use within the VB(A) Editor.
    Where design mode gets used (at least in Word) is if you are using the Control Toolbox toolbar, within the Word interface, to add ActiveX controls directly into the document (i.e. not contained within a userform).
    When you deal with controls in this way, you can switch between design mode and (not sure its official name) run mode. There's a button on the Control Toolbox toolbar that lets you do this, and it appears that you can do the same by using the Design Mode command in the VB Editor.

    2. Reset ends execution of the code - it takes you out of Break mode and clears all memory that may be assigned to variables - never thought of it that way, but it seems a safe assumption that this exonerates you from having to use those Set to Nothing statements in the Immediate Window.

    Gary

  3. #3
    JustCallMeAl
    Guest

    Re: SAMs Learn...21 days.

    Thanks for the clarification.

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

    Re: SAMs Learn...21 days.

    Actually, VB is always in design mode too, unless you run the application. One difference is that in VB you can't just compile the code, you have to do a Run with Full Compile, or some such, so you only find your mistakes at run time.

    You're wrong about the second item. It only "sort of" destroys the object variables, but it doesn't release the resources that they appropriated. So if you keep ending the code without destroying the objects explicitly, you'll eventually receive an Out of Memory error. In VB, you'll get the same thing by not putting an End in your main close routine.
    Charlotte

  5. #5
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SAMs Learn...21 days.

    Hi Charlotte,

    How would this relate to a userform in Excel2000? In other words, which would be better, userform.hide or userform.unload? Or is there any difference? Does unloading a userform remove the memory resources allocated to keeping it around (or whatever happens to it when it is hidden)?

    Thanks,

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

    Re: SAMs Learn...21 days.

    Using unload releases the resources but it's slower if you're going to display the form again. It doesn't matter which application you're in, that stays the same. The decision on which to use has to be based on how you're going to use the form in that particular application. For example, it's pretty standard to load all your forms at startup in a VB project to avoid delays loading them. But the ones that you may only look at once (like Help-->About) probably can be unloaded once they've been looked at.
    Charlotte

  7. #7
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: SAMs Learn...21 days.

    Charlotte,

    Thanks for (as always) shining a beam of light in the darkness :-).

    Your second comment leaves me wanting more info - how do you determine when resources have been released and when they're still being held on to? - if I track this in the Locals Window while stepping through code or running to a break point, everything in the Locals Window blanks out if I end execution with Reset (as you'd expect since the program has ended).

    Is there another tool that can be used to determine whether there are unreleased variables still hanging around in electronic limbo?

    Gary

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

    Re: SAMs Learn...21 days.

    I don't know of any tools, although there may be some out there. An Out of Memory message is a pretty good indicator that resources haven't been released, though. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> Memory allocation is actually a Windows problem, and there are resource monitors in at least some of the Windows resource kits. I know the NT monitor can get horribly detailed on the resources in use, but it won't go down to the variable level. Sorry. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

    Seriously, I think this comes down to clean, carefully written code that explicitly unloads forms that aren't needed and destroys object variables as soon as THEY are no longer needed. It's very frustrating to walk through code one line at a time looking for the one undestroyed object that's keeping your database open, for example. So I usually write the Set Whatever = Nothing right after I set the object variable. Then I fill in the code in between. It's kind of like If End If. I usually do the same thing there to avoid trying to backtrack through nested Ifs to find the one that's missing it's End If.
    Charlotte

Posting Permissions

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