Consulting

Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 21 to 40 of 47

Thread: Solved: Set Variables to Nothing

  1. #21
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Gerry,
    Welcome to the Excel forum.
    Nice point about long/string. Sometimes the obvious is hard to see!
    Regards
    Malcolm
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  2. #22
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by mdmackillop
    4. Not be pedandic about contributors setting variables to Nothing in KB entries.
    Hi Malcom,

    I do hope you reconsider that part. Cause clearing Objects explicitly with the keyword Nothing is still considerd good programming practise. And we do try to spread that kind of gospel with our knowledgebase...

    We have talked about this subject before in the approvers forum but I can't find the thread al that easily but IMO we agreed on checking for correct closing and clearing of object references. (amongst things) A lot of KB's are checked on that issue.

    Of course the decesion is up to you.
    5. Sleep happy with the thought that if I forgot to release a variable, then the VBA gods will have taken pity on the little creature and done it for me.
    Thanks to all.
    Amen to that brother!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  3. #23
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by fumei
    YOU BLOODY WELL CAN'T!
    Please STOP Gerry you're killing ME!

    Quote Originally Posted by mdmackillop
    Hi Gerry,
    Welcome to the Excel forum.
    Priceless...
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  4. #24
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by MOS MASTER
    We have talked about this subject before in the approvers forum but I can't find the thread al that easily but IMO we agreed on checking for correct closing and clearing of object references. (amongst things) A lot of KB's are checked on that issue.
    One reason I don't do KBs, I got fed up of getting them returned for insignificant matters, and being forced to use Americanisms.

  5. #25
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Killing you? Well I certainly don't want that.

  6. #26
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by fumei
    As for those who bring in the question, why don't you reset Long, String etc variables?

    Excuse me people....but have you actually even tried?????? There is a damn good reason why we don't reset Long, String etc variables...

    YOU BLOODY WELL CAN'T!
    That was a typo on my part, I meant strings and arrays, so used to writing strings and longs I was in auto.

    And you BLOODY WELL CAN clear strings, as the larger they are, the more memory they take. Ditto arrays.

    Quote Originally Posted by fumei
    So...yeah...there is a reason we don't set Long, String to Nothing. They are NOT objects, and you can't set them to nothing.
    The only one to mention setting a string to nothing so far is you!

    Quote Originally Posted by fumei
    So. The questions really is. Does VBA actually clean up OBJECT variables the same way it cleans up NON-OBJECT variables?

    Who the hell knows? I sure don't.
    But do you know it doesn't? Don't bother answering that, you might rant on about modules not being strings.

    Quote Originally Posted by fumei
    The argument about HEY! why not reset Long, Strings etc is moot. Toss it. I am surprised Matt Curland used it, as it is totally a bogus red herring.
    He didn't re Longs, as I said above it was my typo.

  7. #27
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by xld
    One reason I don't do KBs, I got fed up of getting them returned for insignificant matters, and being forced to use Americanisms.
    I'm sorry you feel that way but I can totally relate to what you're saying. (A PITA though we lost you in that way cause you're are a very knowledgable person....)

    Perhaps things will change in the future.
    </IMG>
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  8. #28
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by MOS MASTER
    I'm sorry you feel that way but I can totally relate to what you're saying. (A PITA though we lost you in that way cause you're are a very knowledgable person....)

    Perhaps things will change in the future.
    </IMG>
    Oddly enough, I hadn't noticed before, but my VBA ranking is greater than that possible for someone with only 3 KBs

  9. #29
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    So if it works without it why do it. Couldn't the same be said for Option Explicit?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  10. #30
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by xld
    Oddly enough, I hadn't noticed before, but my VBA ranking is greater than that possible for someone with only 3 KBs
    I did notice that before... Wouldn't know why...
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  11. #31
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by lucas
    So if it works without it why do it. Couldn't the same be said for Option Explicit?
    Steve it's NOT I repeat NOT proven yet that it does always work without it. But I agree it's a mather of preference if you use it.

    And No Option Explicit is a totaly different subject and again relates to good programming practices and it helps you in many ways (example: by forcing you to declare your variables) writing your code.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  12. #32
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I don't see where anything has been proven here one way or the other......The subject was good programing practice
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  13. #33
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by lucas
    I don't see where anything has been proven here one way or the other......The subject was good programing practice
    If you mean it in that way the you should use it cause its considered good programming practice.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  14. #34
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Quote Originally Posted by lucas
    So if it works without it why do it.
    I think that's the underlying question here. I think that article by Matt Curland was very informative and educational. It will probably change some coding habits of mine and provoke some other testings to be completed.

    Quote Originally Posted by lucas
    Couldn't the same be said for Option Explicit?
    I agree with Joost, it's not the same.


    Thanks for such a thought provoking post MD! And to all those contributing, this truly is a great thread!

  15. #35
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I'm just saying that our forum is directed towards folks learning(myself included). So shouldn't we be using top of the line methods as examples. Lots of code posted here without option explicit but when we publish to the kb its a different story. Hopefully this thread will help us sort and define what is good programing practice and we can come to a consensus on the subject.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  16. #36
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by lucas
    I'm just saying that our forum is directed towards folks learning(myself included). So shouldn't we be using top of the line methods as examples. Lots of code posted here without option explicit but when we publish to the kb its a different story. Hopefully this thread will help us sort and define what is good programing practice and we can come to a consensus on the subject.
    Steve,

    I think I agree with you on the first part. Neither Option Explicit nor setting to Nothing will give a problem ... in 99.9% of the cases (for serious developers).

    But I know for a fact that Option Explicit save me making an error of wrongly using a variable that I haven't declared, and therby giving me a logic problem that might be very difficult to track down.

    Others are saying that not setting object variables to nothing can also casue problems. Again, not every time perhaps, but again I would imagine that such a problem would be a bugger to track down.

    As such, it could be argued that both are good examples of defensive programming. To my mind, that is nothing to do with style, but it is to do with programming practice. I definitely use Option Explicit implicitly, and I tend to also set object variables to Nothing, but not as religiously, because it doesn't hurt, and if it saves a problem down the line, then I am ahead of the game.

  17. #37
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by firefytr
    I think that's the underlying question here. I think that article by Matt Curland was very informative and educational. It will probably change some coding habits of mine and provoke some other testings to be completed.
    Then you should get hold of his book, it will turn your coding world upside down.

    And if you do get it, and you then understand it, perhaps you could explain it to me

  18. #38
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by MOS MASTER
    Steve it's NOT I repeat NOT proven yet that it does always work without it.
    It never will be, always is infinite. Can only prove the converse.

  19. #39
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by xld
    As such, it could be argued that both are good examples of defensive programming. To my mind, that is nothing to do with style, but it is to do with programming practice. I definitely use Option Explicit implicitly, and I tend to also set object variables to Nothing, but not as religiously, because it doesn't hurt, and if it saves a problem down the line, then I am ahead of the game.
    On this I agree in FULL!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  20. #40
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by xld
    It never will be, always is infinite. Can only prove the converse.
    The holy grail will come to us eventually! (let's hope one of us stumbles up on it soon...)
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

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