Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables validity

Status
Not open for further replies.

Enkay62

Programmer
Sep 5, 2003
78
IT
Hi.
Maybe this is a very stupid question, but, anyway.....
As far as I know, we can declare variables whose validity depends on their typology (local, global, etc...).
In any case, nevertheless, no variable's value is "Saved".
Let's assume I've the following code

Sub UserForm_Initialize()
Dim myvar as integer
If OptionButton1 = True Then
myvar = 1
Else
Myvar = 0
end if
end sub

Let's assume that users click OptionButton1 (=True)

When code is terminated or form closed, when I load userform1 again, Myvar won't have value 1, unless I click OptionButton1 again.
So, to save users choices until next change, I've solved my problem by mean of "Control source" property.
(OptionButton1.ControlSource="Sheet1!A1" and, in "Initialize" event:
If Worksheets("Sheet1").Range("A1")=1 Then
OptionButton1.value=False
else
OptionButton1.value=True
etc.....)

In fact, value of cells is not temporary and it's saved with all data in worksheet.
I'm sure there's another way to save data in variables, but I don't know.
Thank you for your kind suggestions.
Regards.
Nick.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top