Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Disappearance of assigned value of varaible when working with form

I have a strange problem with Excel 97 (I think this problem is
existing in the later versions also). Here is a simplified version of what I
did.

I created three command buttons in sheet1 and a userform in the
project. When I display a form and then come back to the xlsheet, the values
I assigned before for all variables are lost.

I wrote the following code:

Standard module:
Public x as integer

Sheet1:
Private Sub CommandButton1_Click()
Load UserForm1
End Sub

Private Sub CommandButton2_Click()
x = 4
UserForm1.show
End Sub

Private Sub CommandButton3_Click()
MsgBox x
End Sub

Userform1:
Private Sub Userform_Click()
UserForm1.hide
End Sub

This is what I do when I run the program:

I click buttons 1 and 2. Userform1 is displayed. When I click the form,
it disappears. Then I click button 3. Now the messagebox displays the value 0
for x. What happened to the value I assigned to x in the click procedure of
button 2?

If I remove the 'Userform1.show' command from the the click procedure of
button2, and repeat the above steps, I get the value 4 for x displayed in the
messagebox. Can anyone explain? Strange isn't it!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Disappearance of assigned value of varaible when working with form

http://support.microsoft.com/default...b;en-us;169621
OFF97: Displaying UserForm Designer Resets Global Variables

Believe this is only in Office 97.

--
Regards,
Tom Ogilvy



"vbaprog" wrote in message
...
I have a strange problem with Excel 97 (I think this problem is
existing in the later versions also). Here is a simplified version of what

I
did.

I created three command buttons in sheet1 and a userform in the
project. When I display a form and then come back to the xlsheet, the

values
I assigned before for all variables are lost.

I wrote the following code:

Standard module:
Public x as integer

Sheet1:
Private Sub CommandButton1_Click()
Load UserForm1
End Sub

Private Sub CommandButton2_Click()
x = 4
UserForm1.show
End Sub

Private Sub CommandButton3_Click()
MsgBox x
End Sub

Userform1:
Private Sub Userform_Click()
UserForm1.hide
End Sub

This is what I do when I run the program:

I click buttons 1 and 2. Userform1 is displayed. When I click the

form,
it disappears. Then I click button 3. Now the messagebox displays the

value 0
for x. What happened to the value I assigned to x in the click procedure

of
button 2?

If I remove the 'Userform1.show' command from the the click procedure

of
button2, and repeat the above steps, I get the value 4 for x displayed in

the
messagebox. Can anyone explain? Strange isn't it!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Disappearance of assigned value of varaible when working with

Hai,
Thank you for the answer. Is there some way to retain the value of
these variables after returning from the form to the xl sheet? Thanks in
advance

"Tom Ogilvy" wrote:

http://support.microsoft.com/default...b;en-us;169621
OFF97: Displaying UserForm Designer Resets Global Variables

Believe this is only in Office 97.

--
Regards,
Tom Ogilvy



"vbaprog" wrote in message
...
I have a strange problem with Excel 97 (I think this problem is
existing in the later versions also). Here is a simplified version of what

I
did.

I created three command buttons in sheet1 and a userform in the
project. When I display a form and then come back to the xlsheet, the

values
I assigned before for all variables are lost.

I wrote the following code:

Standard module:
Public x as integer

Sheet1:
Private Sub CommandButton1_Click()
Load UserForm1
End Sub

Private Sub CommandButton2_Click()
x = 4
UserForm1.show
End Sub

Private Sub CommandButton3_Click()
MsgBox x
End Sub

Userform1:
Private Sub Userform_Click()
UserForm1.hide
End Sub

This is what I do when I run the program:

I click buttons 1 and 2. Userform1 is displayed. When I click the

form,
it disappears. Then I click button 3. Now the messagebox displays the

value 0
for x. What happened to the value I assigned to x in the click procedure

of
button 2?

If I remove the 'Userform1.show' command from the the click procedure

of
button2, and repeat the above steps, I get the value 4 for x displayed in

the
messagebox. Can anyone explain? Strange isn't it!




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
Name Assigned Formula Not Working FARAZ QURESHI Excel Discussion (Misc queries) 3 December 31st 08 08:41 AM
Hyperlink varaible substitution - How To Sledge Bacon Excel Worksheet Functions 10 May 29th 08 06:03 PM
Disappearance of Sheet Numbers Wquinn New Users to Excel 1 December 12th 05 02:12 AM
Passing a named varaible to Excel's Autofilter Jeff Glock Excel Programming 1 December 23rd 03 04:46 PM
combo box selection disappearance chris[_7_] Excel Programming 1 October 3rd 03 07:36 PM


All times are GMT +1. The time now is 05:45 PM.

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"