![]() |
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 -- DJB ------------------------------------------------------------------------ DJB's Profile: http://www.excelforum.com/member.php...o&userid=21221 View this thread: http://www.excelforum.com/showthread...hreadid=384286 |
What are my variables ... ?
In reality not declaring variables/functions etc is a bad thing becaus it slows down the execution time of the various routines and als allows incorrect data to be assigned (such as strings to numerics etc) Put Code ------------------- Option Explicit ------------------- at the top of each module and then use the Compile function to attemp to compile your code. It will stop at each undeclared variable. Don't forget that functions also need typing: Code ------------------- Function My_Func(Arg1 as Integer, Arg2 as String) as String ------------------- As for the benefits of "compiling" it highlights any errors before you user see's them! Regards Ric -- Rich_ ----------------------------------------------------------------------- Rich_z's Profile: http://www.excelforum.com/member.php...fo&userid=2473 View this thread: http://www.excelforum.com/showthread.php?threadid=38428 |
What are my variables ... ?
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 |
What are my variables ... ?
Heh! The first line of code I always type (if VB is not set up to do it is: OPTION EXPLICIT Regards Ric -- Rich_ ----------------------------------------------------------------------- Rich_z's Profile: http://www.excelforum.com/member.php...fo&userid=2473 View this thread: http://www.excelforum.com/showthread.php?threadid=38428 |
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 |
All times are GMT +1. The time now is 08:10 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com