Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Basic question - modules and class modules - what's the difference? | Excel Programming | |||
Problem with Userform and different code modules | Excel Programming | |||
When to code in sheet or userform modules and when to use modules | Excel Programming | |||
Userform with template class module problem | Excel Programming | |||
Userform with template class module problem | Excel Programming |