PC Review


Reply
Thread Tools Rate Thread

Confusion about context of variable

 
 
davegb
Guest
Posts: n/a
 
      20th Mar 2007
I'm working on some code that asks the user via userform to select a
checkbox if they want a certain result. I've publicly declared a
boolean variable bHdr to capture whether they've selected the box
(true) or not (false). I checked to made sure the result of that
selection was passed from the userform code back to the original macro
by putting a watch on the variable in the userform code. When control
passed back to the original macro, the value of bHdr became "empty".
Then I put a separate watch on the variable bHdr in the original code.
It shows the variable having a value "true" if I checked the
checkbox.

I'm confused about this. If the variable is declared publicly, why is
it empty in the context of the userform once it is closed, but true in
the context of the module? What does this mean? Exactly how does VBA
handle this kind of variable?

 
Reply With Quote
 
 
 
 
paul.robinson@it-tallaght.ie
Guest
Posts: n/a
 
      20th Mar 2007
Hi
Public variables defined in code modules behind userforms are
properties of the form, so I guess they are destroyed when the form
is.
On the other hand, if your public variable IN THE CODE MODULE FOR THE
USERFORM is called TestBoolea.n thenwhen you call the userform you can
do:

Userform1.Show
myBoolean = Userform1.TestBoolean
Unload Userform1

regards
Paul

On Mar 20, 2:50 pm, "davegb" <dav...@safebrowse.com> wrote:
> I'm working on some code that asks the user via userform to select a
> checkbox if they want a certain result. I've publicly declared a
> boolean variable bHdr to capture whether they've selected the box
> (true) or not (false). I checked to made sure the result of that
> selection was passed from the userform code back to the original macro
> by putting a watch on the variable in the userform code. When control
> passed back to the original macro, the value of bHdr became "empty".
> Then I put a separate watch on the variable bHdr in the original code.
> It shows the variable having a value "true" if I checked the
> checkbox.
>
> I'm confused about this. If the variable is declared publicly, why is
> it empty in the context of the userform once it is closed, but true in
> the context of the module? What does this mean? Exactly how does VBA
> handle this kind of variable?



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable not yet created in this context forger Microsoft Excel Programming 1 12th Oct 2008 08:11 PM
Variable type Confusion =?Utf-8?B?RCBaYW5kdmVsZA==?= Microsoft Excel Programming 2 5th Mar 2007 09:07 AM
Variable Property/field scope confusion garyusenet@myway.com Microsoft C# .NET 9 24th Nov 2006 03:15 PM
.NET 2.0 Profile variable replaces Session except 'profile' does not exist in the current context err j-in-uk Microsoft C# .NET 3 11th Jul 2006 02:01 PM
Re: use Context or a Page variable? Steve C. Orr, MCSD Microsoft ASP .NET 0 12th Aug 2003 11:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:15 AM.