Results 1 to 3 of 3
  1. #1

    Poor Programming Practices

    I am a student working in a Co-op position doing programming. I am having a lot of fun and learning lots. I am afraid that I do not have any other computer people to learn from and as such learn most of what I know on my own or here.

    The reason I state all that is because I think I have been using poor programming practices. I have not been setting any of my Dim objects to none. Before I go to much further I would like to go back and fix my code. I was wondering if there was a sight on the net that had good examples on the best way of doing so and/or good rules of when it needs to be done.

    Thank you very much! <img src=/S/baby.gif border=0 width=15 height=15>

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Sacramento, California, USA
    Thanked 1 Time in 1 Post

    Re: Poor Programming Practices

    If by "none" you mean "=Nothing", you need to do that for object variables only. So for things like Database, Recordset, Property, Control, Form, Report, TableDef, etc., you need to include a Set obj = Nothing to destroy the instance of the variable. In theory this shouldn't be necessary, but in practice it is.

    The standard is to dim your variables at the beginning of a routine so that they are easily found when you need to read your code. They should be destroyed as soon as you don't need them anymore, i.e., as soon as you finish using a recordset, issue a close method call. To keep from having an error cause your code to bypass cleaning up your objects, have a "cleanup and exit" portion at the end of your code but above the error handling and make sure it closes and destroys all your object variables. In case they've already been properly destroyed, you need to put in an "on error resume next" at the beginning of the "cleanup and exit". Don't forget to put in an Exit Sub or Exit Function so you don't drop right into your error handler.

    There are Access tutorials in various places on the Web, and several have been recommended in other threads. Try doing a search on tutorial and see what you get.

  3. #3

    Re: Poor Programming Practices

    Thanks Charlotte!
    That was a lot of info!
    Thanks for the trouble.

Posting Permissions

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