+ Reply to Thread
Results 1 to 8 of 8

memory:Variables

  1. #1
    Mike NG
    Guest

    memory: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

  2. #2
    Rob Bovey
    Guest

    re: memory:Variables

    "Mike NG" <[email protected]> wrote in message
    news:[email protected]...
    >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



  3. #3
    Mike NG
    Guest

    re: memory:Variables

    On Thu, 2 Jun 2005 at 12:23:28, Rob Bovey (Rob Bovey
    <[email protected]>) 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

  4. #4
    Dave Peterson
    Guest

    re: memory: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
    > <[email protected]>) 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

  5. #5
    Mike NG
    Guest

    re: memory:Variables

    On Fri, 3 Jun 2005 at 08:51:03, Dave Peterson (Dave Peterson
    <[email protected]>) 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

  6. #6
    Dave Peterson
    Guest

    re: memory: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
    > <[email protected]>) 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

  7. #7
    Mike NG
    Guest

    re: memory:Variables

    On Fri, 3 Jun 2005 at 17:27:51, Dave Peterson (Dave Peterson
    <[email protected]>) 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

  8. #8
    Mike NG
    Guest

    re: memory:Variables

    On Thu, 2 Jun 2005 at 19:59:41, Mike NG (Mike NG
    <[email protected]>) 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

+ 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