Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Public Variable Question

Win XP Excel 2003

I believe that the value assigned to a Public Variable will survive
from module to module during Runtime.
If a Userform is made to Show during Runtime,
then remains static awaiting user input, is the value
that was assigned to the Public Variable still available,
before the Userform is Unloaded.
donwb


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Public Variable Question

Yes.


"donwb" wrote in message
...
Win XP Excel 2003

I believe that the value assigned to a Public Variable will survive
from module to module during Runtime.
If a Userform is made to Show during Runtime,
then remains static awaiting user input, is the value
that was assigned to the Public Variable still available,
before the Userform is Unloaded.
donwb



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Public Variable Question

It should be unchanged until you change it.

But there are things that you can do to lose the value.

Your code could have an "End" statement in it--not "End Function", not "End
Sub", not "End Select", just a plain old End statement:

if somevar = false then
end
end if

This is a quick, but horrible way to exit the sub/function.

You could Reset in the VBE (Run|Reset or hit the reset button) when you're
testing your code.

I like this technique:

Option Explicit
Public VarsAreDefined as boolean
Public SomeVar1 as string
public SomeVar2 as Variant

....

Then have a procedure that sets the variables:

Option Explicit
Sub DefineMyVars()
VarsAreDefined = true
SomeVar1 = "somestring"
SomeVar2 = thisworkbook.worksheets("Sheet1").range("A1").valu e
end sub

Then before you try to use any of those variables in any of your routines, you
can do:

if varsaredefined then
'keep going
else
call DefineMyVars
end if


donwb wrote:

Win XP Excel 2003

I believe that the value assigned to a Public Variable will survive
from module to module during Runtime.
If a Userform is made to Show during Runtime,
then remains static awaiting user input, is the value
that was assigned to the Public Variable still available,
before the Userform is Unloaded.
donwb


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Public Variable Question

Many thanks for the input Gents

I'm glad the bottom line to my question is yes,
because I didn't want to embark on wild goose chase.

I'll keep in mind your suggestions Dave

grateful
donwb

"Dave Peterson" wrote in message
...
It should be unchanged until you change it.

But there are things that you can do to lose the value.

Your code could have an "End" statement in it--not "End Function", not
"End
Sub", not "End Select", just a plain old End statement:

if somevar = false then
end
end if

This is a quick, but horrible way to exit the sub/function.

You could Reset in the VBE (Run|Reset or hit the reset button) when you're
testing your code.

I like this technique:

Option Explicit
Public VarsAreDefined as boolean
Public SomeVar1 as string
public SomeVar2 as Variant

...

Then have a procedure that sets the variables:

Option Explicit
Sub DefineMyVars()
VarsAreDefined = true
SomeVar1 = "somestring"
SomeVar2 = thisworkbook.worksheets("Sheet1").range("A1").valu e
end sub

Then before you try to use any of those variables in any of your routines,
you
can do:

if varsaredefined then
'keep going
else
call DefineMyVars
end if


donwb wrote:

Win XP Excel 2003

I believe that the value assigned to a Public Variable will survive
from module to module during Runtime.
If a Userform is made to Show during Runtime,
then remains static awaiting user input, is the value
that was assigned to the Public Variable still available,
before the Userform is Unloaded.
donwb


--

Dave Peterson



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Public Variable Question

yes.

If the idea is to maintain data from a userform, then don't unload the form,
just hide it.


"donwb" wrote in message
...
Win XP Excel 2003

I believe that the value assigned to a Public Variable will survive
from module to module during Runtime.
If a Userform is made to Show during Runtime,
then remains static awaiting user input, is the value
that was assigned to the Public Variable still available,
before the Userform is Unloaded.
donwb



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Public variable (or Public Const?) Brettjg Excel Programming 14 April 23rd 09 11:30 PM
Public variable (or Public Const?) Tim Williams[_2_] Excel Programming 0 April 23rd 09 06:33 AM
public variable question Gary Keramidas Excel Programming 3 April 26th 07 04:57 AM
Declaration of public variable - Question Les Stout[_2_] Excel Programming 2 October 5th 05 02:53 PM
Public Variable Jason Excel Programming 4 April 12th 04 07:06 PM


All times are GMT +1. The time now is 09:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"