Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Public Variables

I have a file with 3 userforms and 1 module. In userfor1
I have declared a public variable:

Public SheetExcludeArray As Variant

The first part of this form calls userform2 which
populates the array. On userform2 I populate this array
and the Debug.Print tells me the values are present
within the procedcures that support useform2. When I am
finished with this form I Unload it and this takes me
back to userform1. When I complete the rest of userform1
my main routine is called. The main routine uses teh
values from the array I populated. However the values
are not longer present. Is this becuase I am unloading
the form?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Public Variables

Or is this because public variables do not have the scope
across userforms? That originally I was generating the
array in a sub within userform1 that was creating another
temporary userform(dilaogue sheets). The final sub that
used the array was in a sub that was within userform1.

I have done away with teh dilog sheets and have had to
build a second userform. Is the issue that I actually
popeulate the array in userfor2 but now need to pass it
to userform1 so the sub in userform1 can use it? This is
confusing too becuase I was able to populate the array in
userform 2 without declaring it But the again, I was not
in Option Explict mode either......ummmmmmm.



-----Original Message-----
I have a file with 3 userforms and 1 module. In

userfor1
I have declared a public variable:

Public SheetExcludeArray As Variant

The first part of this form calls userform2 which
populates the array. On userform2 I populate this array
and the Debug.Print tells me the values are present
within the procedcures that support useform2. When I am
finished with this form I Unload it and this takes me
back to userform1. When I complete the rest of

userform1
my main routine is called. The main routine uses teh
values from the array I populated. However the values
are not longer present. Is this becuase I am unloading
the form?

Thanks
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Public Variables

Declare the public variable in you general module.

Public variables in a class module (such as a userform) have scope within
the form.

You could address it as a property of the form

Userform1.SheetExcludeArray

Also, your current use in Userform2 is working with a different
SheetExcludeArray.

But if you unload the form, it is gone. So better to declare it in your
module.

--
Regards,
Tom Ogilvy

"ExcelMonkey" wrote in message
...
Or is this because public variables do not have the scope
across userforms? That originally I was generating the
array in a sub within userform1 that was creating another
temporary userform(dilaogue sheets). The final sub that
used the array was in a sub that was within userform1.

I have done away with teh dilog sheets and have had to
build a second userform. Is the issue that I actually
popeulate the array in userfor2 but now need to pass it
to userform1 so the sub in userform1 can use it? This is
confusing too becuase I was able to populate the array in
userform 2 without declaring it But the again, I was not
in Option Explict mode either......ummmmmmm.



-----Original Message-----
I have a file with 3 userforms and 1 module. In

userfor1
I have declared a public variable:

Public SheetExcludeArray As Variant

The first part of this form calls userform2 which
populates the array. On userform2 I populate this array
and the Debug.Print tells me the values are present
within the procedcures that support useform2. When I am
finished with this form I Unload it and this takes me
back to userform1. When I complete the rest of

userform1
my main routine is called. The main routine uses teh
values from the array I populated. However the values
are not longer present. Is this becuase I am unloading
the form?

Thanks
.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Public Variables

Sorry Tom but I am confused. I have two userforms.
Userform1 calls Userform2. Userform2 loads an array and
takes the user back to userform1. Userform1 has my main
routine. This main routine does not recognize the array
loaded in Userform2. I want this array available to all
of the routines behined Userform1 and perhaps others as
well.

Do I:
1)Declare array as public in Userform2
2)Delcare array as public in Userform1
3)Delare array as public in a Class Module

Thanks and sorry for the confusion.



-----Original Message-----
Declare the public variable in you general module.

Public variables in a class module (such as a userform)

have scope within
the form.

You could address it as a property of the form

Userform1.SheetExcludeArray

Also, your current use in Userform2 is working with a

different
SheetExcludeArray.

But if you unload the form, it is gone. So better to

declare it in your
module.

--
Regards,
Tom Ogilvy

"ExcelMonkey"

wrote in message
...
Or is this because public variables do not have the

scope
across userforms? That originally I was generating the
array in a sub within userform1 that was creating

another
temporary userform(dilaogue sheets). The final sub

that
used the array was in a sub that was within userform1.

I have done away with teh dilog sheets and have had to
build a second userform. Is the issue that I actually
popeulate the array in userfor2 but now need to pass it
to userform1 so the sub in userform1 can use it? This

is
confusing too becuase I was able to populate the array

in
userform 2 without declaring it But the again, I was

not
in Option Explict mode either......ummmmmmm.



-----Original Message-----
I have a file with 3 userforms and 1 module. In

userfor1
I have declared a public variable:

Public SheetExcludeArray As Variant

The first part of this form calls userform2 which
populates the array. On userform2 I populate this

array
and the Debug.Print tells me the values are present
within the procedcures that support useform2. When I

am
finished with this form I Unload it and this takes me
back to userform1. When I complete the rest of

userform1
my main routine is called. The main routine uses teh
values from the array I populated. However the values
are not longer present. Is this becuase I am

unloading
the form?

Thanks
.



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Public Variables

with your project as the activeproject (selected in the project explorer)
do Insert = Module

Declare it there outside any procedure (at the very top).

Don't declare it anywhere else; remove all existing declarations.

--
Regards,
Tom Ogilvy

"ExcelMonkey" wrote in message
...
Sorry Tom but I am confused. I have two userforms.
Userform1 calls Userform2. Userform2 loads an array and
takes the user back to userform1. Userform1 has my main
routine. This main routine does not recognize the array
loaded in Userform2. I want this array available to all
of the routines behined Userform1 and perhaps others as
well.

Do I:
1)Declare array as public in Userform2
2)Delcare array as public in Userform1
3)Delare array as public in a Class Module

Thanks and sorry for the confusion.



-----Original Message-----
Declare the public variable in you general module.

Public variables in a class module (such as a userform)

have scope within
the form.

You could address it as a property of the form

Userform1.SheetExcludeArray

Also, your current use in Userform2 is working with a

different
SheetExcludeArray.

But if you unload the form, it is gone. So better to

declare it in your
module.

--
Regards,
Tom Ogilvy

"ExcelMonkey"

wrote in message
...
Or is this because public variables do not have the

scope
across userforms? That originally I was generating the
array in a sub within userform1 that was creating

another
temporary userform(dilaogue sheets). The final sub

that
used the array was in a sub that was within userform1.

I have done away with teh dilog sheets and have had to
build a second userform. Is the issue that I actually
popeulate the array in userfor2 but now need to pass it
to userform1 so the sub in userform1 can use it? This

is
confusing too becuase I was able to populate the array

in
userform 2 without declaring it But the again, I was

not
in Option Explict mode either......ummmmmmm.



-----Original Message-----
I have a file with 3 userforms and 1 module. In
userfor1
I have declared a public variable:

Public SheetExcludeArray As Variant

The first part of this form calls userform2 which
populates the array. On userform2 I populate this

array
and the Debug.Print tells me the values are present
within the procedcures that support useform2. When I

am
finished with this form I Unload it and this takes me
back to userform1. When I complete the rest of
userform1
my main routine is called. The main routine uses teh
values from the array I populated. However the values
are not longer present. Is this becuase I am

unloading
the form?

Thanks
.



.





  #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.

--

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
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 06:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"