LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Public Variables

Perhaps the usage of public variables is confusing the OP. The rule of
thumb is too to minimize scoping and public variables aren't required
in this scenario e.g.

' ---<Userform2 code module---
Option Explicit
Private m_strMyArray() As String

Private Sub UserForm_Activate()
LoadArray
End Sub

Sub LoadArray()
ReDim m_strMyArray(2)
m_strMyArray(0) = "No"
m_strMyArray(1) = "Public"
m_strMyArray(2) = "Variables"
End Sub

Public Property Get MyArray() As Variant
MyArray = m_strMyArray
End Property

Private Sub UserForm_QueryClose( _
Cancel As Integer, _
CloseMode As Integer)
Me.Hide
Cancel = True
End Sub
' ---</Userform2 code module---


' ---<Userform1 code module---
Option Explicit

Private Sub UserForm_Click()
Dim TestArray() As String
Dim frm1 As UserForm2
Set frm1 = New UserForm2
With frm1
.Show vbModal
TestArray = .MyArray
End With
' Do things with TestArray here ...
MsgBox TestArray(0) & _
" " & TestArray(1) & _
" " & TestArray(2)

' ... or use a Property to make it
' available to other procedures

End Sub
' ---</Userform1 code module---

Jamie.

--

 
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
public variables johnny Excel Discussion (Misc queries) 7 February 27th 08 03:44 PM
Public variables johnny Excel Discussion (Misc queries) 2 February 24th 08 05:05 AM
Public Variables Jerry McNabb Excel Discussion (Misc queries) 0 February 24th 08 01:26 AM
Public Variables Les Gordon Excel Programming 2 November 11th 04 12:29 PM
Public Variables with UserForms Mark Worthington Excel Programming 3 February 26th 04 12:26 AM


All times are GMT +1. The time now is 01:07 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"