Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default PROBLEM: Keywords;= Userform, Class Modules, ButtonGroup and Nomenclature


I have a Userform with 48 commanbuttons created on the fly via
*ClassModule *named *BClass* and using Array holder *Btns()*.

As we would have it, it is possible to refer to any of th
CommandButtons (say the 15th button) as, by way of example, * Btn
(15).ButtonGroup.Caption *. But this is valid only when such referenc
is made from a *UserForm Module *or *General Module*.

When it is used in a Class Module, * Btns (15).ButtonGroup.Caption
fails, as does, *BClass.Btns(15).ButtonGroup.Caption*. In m
frustration, I have had to get by using a long-winded approach as:

For each ctl in UserForm1.Controls
If TypeOf ctl Is MsForms.CommandButton then
If ctl.Width =60 Then 'optional line
If ct.name ="CommandButton15"
Msgbox *ctl.Caption*
End if
End if
End if
Next

Now, going by the example, what *nomenclature* can be employed t
invoke -the caption of CommandButton15 -*from a Class Module*? the wa
we would use * Btns (15).ButtonGroup.Caption * from a UserFrom modul
or General module?


TIA

Myle

--
Myle
-----------------------------------------------------------------------
Myles's Profile: http://www.excelforum.com/member.php...fo&userid=2874
View this thread: http://www.excelforum.com/showthread.php?threadid=49731

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default PROBLEM: Keywords;= Userform, Class Modules, ButtonGroup and Nomenclature

Show the code that creates the buttons array, it may be re-usable.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Myles" wrote in
message ...

I have a Userform with 48 commanbuttons created on the fly via a
*ClassModule *named *BClass* and using Array holder *Btns()*.

As we would have it, it is possible to refer to any of the
CommandButtons (say the 15th button) as, by way of example, * Btns
(15).ButtonGroup.Caption *. But this is valid only when such reference
is made from a *UserForm Module *or *General Module*.

When it is used in a Class Module, * Btns (15).ButtonGroup.Caption *
fails, as does, *BClass.Btns(15).ButtonGroup.Caption*. In my
frustration, I have had to get by using a long-winded approach as:

For each ctl in UserForm1.Controls
If TypeOf ctl Is MsForms.CommandButton then
If ctl.Width =60 Then 'optional line
If ct.name ="CommandButton15"
Msgbox *ctl.Caption*
End if
End if
End if
Next

Now, going by the example, what *nomenclature* can be employed to
invoke -the caption of CommandButton15 -*from a Class Module*? the way
we would use * Btns (15).ButtonGroup.Caption * from a UserFrom module
or General module?


TIA

Myles


--
Myles
------------------------------------------------------------------------
Myles's Profile:

http://www.excelforum.com/member.php...o&userid=28746
View this thread: http://www.excelforum.com/showthread...hreadid=497315



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default PROBLEM: Keywords;= Userform, Class Modules, ButtonGroup and Nomenclature


Bob,

As requested:

Dim Btns() as New BClass
Sub CreateButtonClass()
Dim ctl as Control

n=1
For each ctl in Me.Controls
If Typename(ctl)="CommandButton" Then
Redim Preserve Btns(1 to n)
Set Btns(n).ButtonGroup=ctl
n=n+1
End if
Next

End su

--
Myle
-----------------------------------------------------------------------
Myles's Profile: http://www.excelforum.com/member.php...fo&userid=2874
View this thread: http://www.excelforum.com/showthread.php?threadid=49731

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default PROBLEM: Keywords;= Userform, Class Modules, ButtonGroup and Nomenclature

Myles,

I have just Googled back a bit as I thought this seemed familiar, and I
found and earlier post where you had a problem and Peter T and I responded.
Peter T said

'could include .Item(8) for clarity

but as I said ... You can't actually. I assumed that Myles was creating a
collection for the buttons within the form which he could then address with
Item, but he is not assigning the controls to an array of the class,
slightly different approach. I like the collection myself :-)).

Moral. I suggest that you use a collection.


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Myles" wrote in
message ...

Bob,

As requested:

Dim Btns() as New BClass
Sub CreateButtonClass()
Dim ctl as Control

n=1
For each ctl in Me.Controls
If Typename(ctl)="CommandButton" Then
Redim Preserve Btns(1 to n)
Set Btns(n).ButtonGroup=ctl
n=n+1
End if
Next

End sub


--
Myles
------------------------------------------------------------------------
Myles's Profile:

http://www.excelforum.com/member.php...o&userid=28746
View this thread: http://www.excelforum.com/showthread...hreadid=497315



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default PROBLEM: Keywords;= Userform, Class Modules, ButtonGroup and Nomenclature


Hi Bob,

This is indeed a sequel to my earlier post which solicited for the way
one can simply refer to a control created as a new collection in a
Class Module. The solution you and Peter T. proffered works like charm!
The only limitation, as I discovered later , is that using an expression
like *Buttons(15).ButtonGroup.Caption *or
-Buttons.Item(15).ButtonGroup.Caption- works but only while you are in
a Userform Module or General Module. To attempt to invoke it *from a
Class Module *draws an error.

How do we get round this problem? I don't seem to have had the clue
yet.

Any ideas?


Myles.


--
Myles
------------------------------------------------------------------------
Myles's Profile: http://www.excelforum.com/member.php...o&userid=28746
View this thread: http://www.excelforum.com/showthread...hreadid=497315



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default PROBLEM: Keywords;= Userform, Class Modules, ButtonGroup and Nomenclature

Hi Myles,

I also recall that thread and seem to remember the "array of class's" method
worked fine for you following some minor modifications, as expected (<g).

Your current problem, as I understand, is you are trying to refer to the
array of class's that you have declared in a Userform. Instead you could
declare the array as public in a normal module, but if you want to keep you
array in your UF (and there are good reasons for doing so) then try
something like this -

' in Userform1 module
Dim Btns() as new BClass

' code to populate Btns

Public Function fnBClass(n As Long) As BClass
Set fnBClass = Btns(n)
End Function

' in BClass module
Private Sub ButtonGroup_Click()
MsgBox UserForm1.fnBClass(3).ButtonGroup.Caption
End Sub

The code you posted suggests Btns() is in the Userform, so I don't follow
how you could access it in a "General Module", as you say you can, without
doing something as above.

Regards,
Peter T


"Myles" wrote in
message ...

Hi Bob,

This is indeed a sequel to my earlier post which solicited for the way
one can simply refer to a control created as a new collection in a
Class Module. The solution you and Peter T. proffered works like charm!
The only limitation, as I discovered later , is that using an expression
like *Buttons(15).ButtonGroup.Caption *or
-Buttons.Item(15).ButtonGroup.Caption- works but only while you are in
a Userform Module or General Module. To attempt to invoke it *from a
Class Module *draws an error.

How do we get round this problem? I don't seem to have had the clue
yet.

Any ideas?


Myles.


--
Myles
------------------------------------------------------------------------
Myles's Profile:

http://www.excelforum.com/member.php...o&userid=28746
View this thread: http://www.excelforum.com/showthread...hreadid=497315



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default PROBLEM: Keywords;= Userform, Class Modules, ButtonGroup and Nomenclature

Myles,

You are not using a collection, but an array, which is why you can reference
that array by index in the userform, but the array cannot be made available
to the class.

One way around would be to use a collection, as that can be made public in
the userform.

However, the simplest way for you is probably to move the buttons()
declaration out of the userform, and declare it Public in a standard code
module. Then, in the class module, you can use code like this

Sub ButtonGroup_Click()
If ButtonGroup.Name = "cmdSubmit" Then
buttons(1).ButtonGroup.BackColor = vbRed
End If
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Myles" wrote in
message ...

Hi Bob,

This is indeed a sequel to my earlier post which solicited for the way
one can simply refer to a control created as a new collection in a
Class Module. The solution you and Peter T. proffered works like charm!
The only limitation, as I discovered later , is that using an expression
like *Buttons(15).ButtonGroup.Caption *or
-Buttons.Item(15).ButtonGroup.Caption- works but only while you are in
a Userform Module or General Module. To attempt to invoke it *from a
Class Module *draws an error.

How do we get round this problem? I don't seem to have had the clue
yet.

Any ideas?


Myles.


--
Myles
------------------------------------------------------------------------
Myles's Profile:

http://www.excelforum.com/member.php...o&userid=28746
View this thread: http://www.excelforum.com/showthread...hreadid=497315



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
Basic question - modules and class modules - what's the difference? Mark Stephens[_3_] Excel Programming 9 May 8th 05 11:48 AM
Problem with Userform and different code modules Jos Vens[_2_] Excel Programming 1 February 23rd 05 09:00 PM
When to code in sheet or userform modules and when to use modules Tony James Excel Programming 1 December 16th 04 10:02 PM
Userform with template class module problem Tom Ogilvy Excel Programming 1 July 18th 03 09:15 PM
Userform with template class module problem Tom Ogilvy Excel Programming 0 July 17th 03 06:38 PM


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