permanently for a couple of days, then I might find the time. Oh and I'd
need to quit the band. Oh and work would need to lay off as well ...
> Thanks again,
> Stratos
> > As an afterthought to the above, I don't normally like the idea of
declaring
> > variables public at the top level (the module usually) so that they can
be
> > changed at the lower levels. IMHO it leads to confusing code (and I
should
> > know I've written a ton of confusing code <g>).
> > I've gradually come to the conclusion that where possible it's better to
put
> > the code which needs to access the userform controls and variables
within
> > the userform itself, possibly even passing the form an object (eg a
Range)
> > on which to act. The next best alternative (IMHO) is to use one instance
of
> > the form and just hide it (as in my previous example) after which the
public
> > variables and controls can be accessed. I've usually found it possible
to
> > adopt one of these styles.
> > --
> > Cheers
> > Mick Jennings
> > ~~~~~~~~~~
> > > Sorry to differ - but you are certainly able to have public variables
in
> > > form modules. I just tried this on XL97.
> > > A simple procedure run from a module ...
> > > ---------------
> > > Option Explicit
> > > Public Sub getvar()
> > > UserForm1.Show
> > > MsgBox UserForm1.myInt
> > > End Sub
> > > --------------
> > > And a simple form with a Checkbox and a CommandButton, code as follows
...
> > > --------------
> > > Option Explicit
> > > Public myInt As Integer
> > > Private Sub CheckBox1_Click()
> > > If CheckBox1 Then
> > > myInt = 10
> > > Else
> > > myInt = 20
> > > End If
> > > End Sub
> > > Private Sub CommandButton1_Click()
> > > Me.Hide
> > > End Sub
> > > -------------------
> > > The above works fine. The trick is to use the command button to "HIDE"
the
> > > form, not to close it. If the user closes the instance of the form
using
> > the
> > > "X" then the msgbox shows "0". If they use the command button then the
> > > correct value is returned, because the form is still active in memory.
It
> > > does, however, prove that public variables are allowed and accessible
> > within
> > > form modules.
> > > --
> > > Cheers
> > > Mick Jennings
> > > ~~~~~~~~~~
> > > > Hi Harri,
> > > > You can store your variables in public variables defined in standard
> > > modules, or you can store it into named workbook-level constants (
> > > > Workbook("aBook").Names.Add ) or on the spreadsheet, or in external
> > files,
> > > or in the registry, etc.
> > > > You are not allowed of public variables in form modules.
> > > > You may also be interested to know that the following can work in
> > > astandard module as well, and its probably the best way (with a
tradeoff
> > > > in coding effort) to manipulate variables (IMHO)
> > > > ----------------------------------------------
> > > > Dim myVariable_Local As Boolean
> > > > Property Let myVariable(aVar As Boolean)
> > > > myVariable_Local = aVar
> > > > End Property
> > > > Property Get myVariable() As Boolean
> > > > myVariable = myVariable_Local
> > > > End Property
> > > > Sub test()
> > > > Module1.myVariable = True
> > > > Debug.Print Module1.myVariable
> > > > End Sub
> > > > -------------------------------------------------
> > > > If you make it Private (i.e. Private Property ...) you can use it as
a
> > > procedure in a form module fully qualifying your syntax (as in the
> > > > example).
> > > > HTH
> > > > Stratos
> > > > > This is from my USERFORM CODE:
> > > > > Public Sub OptionButton2_Change()
> > > > > gameserver = UserForm1.OptionButton2.Value
> > > > > End Sub
> > > > > This is from my MODULE CODE:
> > > > > .....If gameserver = True Then.....
> > > > > How can I store gameserver variable in my USERFORM CODE to use it
> > later
> > > in
> > > > > MODULE CODE???
> > > > > Usually when I declare a variable with Public declaration it can
be
> > used
> > > > > between different modules. But when a variable is declared in
UserForm
> > > Code
> > > > > it is not in use in my modules.
> > > > > I dont want to store the information in excel sheets (cells).
> > > > > --
> > > > > Harri Vesterinen
> > > > > CE-Simulations
> > > > > System development manager
> > > > > mobile. +358 41 461 55 64
> > > > > office. +358 9 406 660
> > > > > fax. +358 9 406 662