+ Reply to Thread
Results 1 to 5 of 5

What are my variables ... ?

  1. #1
    Registered User
    Join Date
    03-17-2005
    Posts
    34

    Wink What are my variables ... ?

    Hello everyone

    I am currently imvolved in a large project, that started off as a very small project, just a few lines of code, that has mushroomed to over a thousand. I have not declared variables in this project, but would now like to, but the problem is there are dozens, if not hundreds. Is there a quick way for me to see/list all the variables so I know what they all are and can start declaring them?

    Secondly, can anyone tell me what is the benefit (if any) of "compiling" the code (Debug ... Compile VBA Project) before I save it, because it does appear to increase the file size, but does it offer any benefits??

    Thanks for reading

    DJB

  2. #2
    Registered User
    Join Date
    06-29-2005
    Location
    England
    Posts
    50
    In reality not declaring variables/functions etc is a bad thing because it slows down the execution time of the various routines and also allows incorrect data to be assigned (such as strings to numerics etc)

    Put

    Please Login or Register  to view this content.
    at the top of each module and then use the Compile function to attempt to compile your code. It will stop at each undeclared variable.

    Don't forget that functions also need typing:

    Please Login or Register  to view this content.
    As for the benefits of "compiling" it highlights any errors before your user see's them!

    Regards

    Rich
    Last edited by Rich_z; 07-04-2005 at 08:47 AM.

  3. #3
    Registered User
    Join Date
    03-17-2005
    Posts
    34
    Hi Richz

    Thanks for your answer. I know it's a bad thing which is why I want to start declaring them.

    Using the Option Explicit line was something I considered, but with the number of variables I have this will take some time because when you do a check the code always stops at the first undeclared variable, irrespective of where the cursor is. I'd have to go back, declare it, run the check again etc. I just wondered if there is a quicker way.

    Strangely enough, I've declared all the variables in my functions, so they're OK.

    DJB

  4. #4
    Registered User
    Join Date
    06-29-2005
    Location
    England
    Posts
    50
    Heh!

    The first line of code I always type (if VB is not set up to do it) is:

    OPTION EXPLICIT

    Regards

    Rich

  5. #5
    Jim Thomlinson
    Guest

    Re: What are my variables ... ?

    There is no quick way to see a list of all of the variables. The compiler
    will not make that distinction until run time when it will create all of your
    variables on the fly. I am with Rich... Add the Option Explicit and then hit
    Debug -> Compile. On the up side you learned to alway declare you variables
    even in small projects. It is a good thing to learn.
    --
    HTH...

    Jim Thomlinson


    "DJB" wrote:

    >
    > Hi Richz
    >
    > Thanks for your answer. I know it's a bad thing which is why I want to
    > start declaring them.
    >
    > Using the Option Explicit line was something I considered, but with the
    > number of variables I have this will take some time because when you do
    > a check the code always stops at the first undeclared variable,
    > irrespective of where the cursor is. I'd have to go back, declare it,
    > run the check again etc. I just wondered if there is a quicker way.
    >
    > Strangely enough, I've declared all the variables in my functions, so
    > they're OK.
    >
    > DJB
    >
    >
    > --
    > DJB
    > ------------------------------------------------------------------------
    > DJB's Profile: http://www.excelforum.com/member.php...o&userid=21221
    > View this thread: http://www.excelforum.com/showthread...hreadid=384286
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1