LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default Show/Hide Userform erases global vriables

Question:
Why does showing and hiding a userform erase all the global variables?
This is in Excel97. Is it different in later versions?

Demo:
A module with only:
Public Globalx%

A Userform with a textbox:
Private Sub TextBox1_KeyDown( _
ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
If KeyCode = 13 Then UserForm1.Hide
End Sub

A sheet with 4 buttons:
Button1 loads Globalx with 1234.
Button2 inputs a number using a listbox.
Button3 inputs a number using a userform.
Button4 displays Globalx.

Hitting buttons 1, 2, and 4: Globalx is still valid.
Hitting buttons 1, 3, and 4: Globalx is lost.

Private Sub CommandButton1_Click()
'-Loads Globalx
CommandButton1.Caption = "Load Globalx"
CommandButton2.Caption = "Inputbox"
CommandButton3.Caption = "Userform"
CommandButton4.Caption = "Display Globalx"
DoEvents ' to see new captions
Globalx = 1234
MsgBox "globalx = " & Globalx
End Sub

Private Sub CommandButton2_Click()
'-Inputs a number using inputbox
Cells(2, 1).Value = _
InputBox("Enter a number", , 4321)
MsgBox "globalx = " & Globalx
End Sub

Private Sub CommandButton3_Click()
'-Inputs a number using userform
UserForm1.Show
Cells(3, 1).Value = _
UserForm1.TextBox1.Value
MsgBox "globalx = " & Globalx
End Sub

Private Sub CommandButton4_Click()
'-Displays Globalx
MsgBox "globalx = " & Globalx
End Sub


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
 
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
Userform Question (Load/Unload/Show/Hide) RPIJG[_76_] Excel Programming 8 November 2nd 05 08:29 PM
How to show/hide sections of a userform? madbloke[_17_] Excel Programming 2 October 6th 04 03:53 PM
Global value does not retain value when UserForm is hide Alex[_15_] Excel Programming 1 November 4th 03 10:03 AM
Userform.hide / show papou[_7_] Excel Programming 0 September 15th 03 03:12 PM
Hide/Show modeless userform when activating/deactivating workbooks Jeremy Gollehon[_2_] Excel Programming 0 August 28th 03 11:05 PM


All times are GMT +1. The time now is 01:12 AM.

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"