![]() |
Variables
I have a spreadsheet with 2 buttons on it, and all the code behind the
sheet I'd prefer it if one particular variable (an array) was "held" at the end of running button1, before I press button2. I can use a DoEvents loop so effectively the program stays running, but I was wondering if there was a better way. It's not a major problem for me, it just means I'm doing a load of processing I don't really need to do had the variable still been in memory -- Mike |
Variables
"Mike NG" wrote in message
... I have a spreadsheet with 2 buttons on it, and all the code behind the sheet I'd prefer it if one particular variable (an array) was "held" at the end of running button1, before I press button2. I can use a DoEvents loop so effectively the program stays running, but I was wondering if there was a better way. It's not a major problem for me, it just means I'm doing a load of processing I don't really need to do had the variable still been in memory Hi Mike, If you declare your variable in the declarations section at the top of the code module outside of any specific procedure that variable will hold its value between button clicks. -- Rob Bovey, Excel MVP Application Professionals http://www.appspro.com/ * Take your Excel development skills to the next level. * Professional Excel Development http://www.appspro.com/Books/Books.htm |
Variables
On Thu, 2 Jun 2005 at 12:23:28, Rob Bovey (Rob Bovey
) wrote: Hi Mike, If you declare your variable in the declarations section at the top of the code module outside of any specific procedure that variable will hold its value between button clicks. Sorry me being stupid. I was already doing this, but I guessed some sort of unexpected end of execution must have happened, cos last time I debugged this it didn't seem to be happening -- Mike |
Variables
Did you click the Reset button (in the VBE)?
Do you have any lines of code with just End on them--not "end sub", "end if", "end function"--just plain old End? Either of those will reset those variables. Mike NG wrote: On Thu, 2 Jun 2005 at 12:23:28, Rob Bovey (Rob Bovey ) wrote: Hi Mike, If you declare your variable in the declarations section at the top of the code module outside of any specific procedure that variable will hold its value between button clicks. Sorry me being stupid. I was already doing this, but I guessed some sort of unexpected end of execution must have happened, cos last time I debugged this it didn't seem to be happening -- Mike -- Dave Peterson |
Variables
On Fri, 3 Jun 2005 at 08:51:03, Dave Peterson (Dave Peterson
) wrote: Do you have any lines of code with just End on them--not "end sub", "end if", "end function"--just plain old End? You've hit the nail on the head there - I've looked at the help for "End" and will consider using "Stop" instead. Glad I wasn't going insane Either of those will reset those variables. -- Mike |
Variables
I don't think you'll want to use Stop--it's used when you're developing your
code. It's gonna try to sit there waiting for you to continue. (Kind of like a breakpoint in the VBE.) Usually, you can wrap your code around some sort of If statement (or Do or any type of conditional statement). Mike NG wrote: On Fri, 3 Jun 2005 at 08:51:03, Dave Peterson (Dave Peterson ) wrote: Do you have any lines of code with just End on them--not "end sub", "end if", "end function"--just plain old End? You've hit the nail on the head there - I've looked at the help for "End" and will consider using "Stop" instead. Glad I wasn't going insane Either of those will reset those variables. -- Mike -- Dave Peterson |
Variables
On Fri, 3 Jun 2005 at 17:27:51, Dave Peterson (Dave Peterson
) wrote: I don't think you'll want to use Stop--it's used when you're developing your code. It's gonna try to sit there waiting for you to continue. (Kind of like a breakpoint in the VBE.) Usually, you can wrap your code around some sort of If statement (or Do or any type of conditional statement). Yeah I did notice the code still running when I tried to exit the debugger. As I'm only in the development stages, the scenarios where I am using "End" are probably critical errors where I need button1 to be pressed after corrections made. I can also control whether buttons are enabled or disabled so I should know the status of everything -- Mike |
Variables
On Thu, 2 Jun 2005 at 19:59:41, Mike NG (Mike NG
) wrote: I have a spreadsheet with 2 buttons on it, and all the code behind the sheet I'd prefer it if one particular variable (an array) was "held" at the end of running button1, before I press button2. I can use a DoEvents loop so effectively the program stays running, but I was wondering if there was a better way. It's not a major problem for me, it just means I'm doing a load of processing I don't really need to do had the variable still been in memory After more investigation I know what "problem" I was having After button1 had finished, I was using Alt-F11 Control-G to display the array variable which was coming back "sub or function not defined". However if I put a breakpoint right at the top of button2 and display it there, it's OK -- Mike |
All times are GMT +1. The time now is 06:47 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com