Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 265
Default problems defining a global variable

Recently I have been needing to use some global variables but I dont know how
to do it, colud some one explainme how to achive this.

Also: I have a form (userform1); this form has 2 chek boxes inside a grouop
box, If chekbox1 is cheked, then I want that the variable a save the "1"
value on it (dim a as integer -- a=1) and if chekbox2 is cheked then a saves
"2", this values of "a" I use them in one of my macros after a button in
userform1 is pressed (button1--unload userform1). Now the problem; My
problem is when userform1 is unloaded, a lost is value, so I dont know which
value ; how to accomplish what I want????
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default problems defining a global variable

Hi,

1. Global variable: at the top of a module, before any SUb , use:
Public a as long

2. For you Userform,
-first , if either checkbox1 OR checkbox2 (but not both) can be selected ,
then use an optionbutton instead of a checkbox. Optionbuttons within a same
groupbox (or Frame) function automatically as you wish... when one is clicked
, the other one is unselected automatically with no need of code.
- now, if the purpose of your form is to return a single value (as if it
were a function), you could do the following:
In your form,add the public Function Displaywhich returns a long:
Public Function Display( ) as Long
Me.Show
If OptionButton1.Value = True then
Display=1
Else
Display=2
End If
End Function

Now from your code , instead of calling
Userform1.Show
call
dim a as Long
a = Userform1.Display( )


Regards,
Sébastien
<http://www.ondemandanalysis.com


"filo666" wrote:

Recently I have been needing to use some global variables but I dont know how
to do it, colud some one explainme how to achive this.

Also: I have a form (userform1); this form has 2 chek boxes inside a grouop
box, If chekbox1 is cheked, then I want that the variable a save the "1"
value on it (dim a as integer -- a=1) and if chekbox2 is cheked then a saves
"2", this values of "a" I use them in one of my macros after a button in
userform1 is pressed (button1--unload userform1). Now the problem; My
problem is when userform1 is unloaded, a lost is value, so I dont know which
value ; how to accomplish what I want????

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 265
Default problems defining a global variable

tanks for your answer

"sebastienm" wrote:

Hi,

1. Global variable: at the top of a module, before any SUb , use:
Public a as long

2. For you Userform,
-first , if either checkbox1 OR checkbox2 (but not both) can be selected ,
then use an optionbutton instead of a checkbox. Optionbuttons within a same
groupbox (or Frame) function automatically as you wish... when one is clicked
, the other one is unselected automatically with no need of code.
- now, if the purpose of your form is to return a single value (as if it
were a function), you could do the following:
In your form,add the public Function Displaywhich returns a long:
Public Function Display( ) as Long
Me.Show
If OptionButton1.Value = True then
Display=1
Else
Display=2
End If
End Function

Now from your code , instead of calling
Userform1.Show
call
dim a as Long
a = Userform1.Display( )


Regards,
Sébastien
<http://www.ondemandanalysis.com


"filo666" wrote:

Recently I have been needing to use some global variables but I dont know how
to do it, colud some one explainme how to achive this.

Also: I have a form (userform1); this form has 2 chek boxes inside a grouop
box, If chekbox1 is cheked, then I want that the variable a save the "1"
value on it (dim a as integer -- a=1) and if chekbox2 is cheked then a saves
"2", this values of "a" I use them in one of my macros after a button in
userform1 is pressed (button1--unload userform1). Now the problem; My
problem is when userform1 is unloaded, a lost is value, so I dont know which
value ; how to accomplish what I want????

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
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
Problems Defining Object Variable in For Each Loop ExcelMonkey[_190_] Excel Programming 7 February 28th 05 10:46 PM
Defining a variable within a sub... aking1987[_3_] Excel Programming 1 November 11th 04 01:12 PM
Defining a variable within a sub... aking1987 Excel Programming 1 November 11th 04 11:00 AM
Defining a Variable Stephen[_3_] Excel Programming 1 September 8th 03 11:33 PM


All times are GMT +1. The time now is 08:38 AM.

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

About Us

"It's about Microsoft Excel"