Class object question -- looping through controls 
Author Message
 Class object question -- looping through controls

Here's what I got...

I've created a class (clsSmoothForms) that has a label and a section
property.  The labels work fine (I use the mouse move, up, and down
events) from the client form.  I also would like to use the section
events to loop through the labels in that section, but it keeps giving
me the "object does not support this property or method" error message
when the event I'm using executes. Here's the code I'm using for the
section:

'    *** Code Start ***
Private WithEvents mDetail As Section
_______________________________________

Public Property Set Section(ByVal secNewDetail As Section)
    Set mDetail = secNewDetail
End Property
_______________________________________

Private Sub mDetail_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
    Dim lbl As Label     ' I only want to mess with the labels

    For Each lbl In mDetail    ' Error happens here
        debug.Print lbl.Name
        lbl.Caption = "Changed" & lbl.Caption
    Next
End Sub

Then, in the client form that will instantiate the class, I have this
code...

Dim cSEC1 As clsSmoothForms
_______________________________________

Private Sub Form_Load()
    Set cSEC1 = New clsSmoothForms

    Set cSEC1.Section = Me.Detail
End Sub
_______________________________________

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
End Sub
_______________________________________

'    *** Code End ***

Is it possible to get the names or modify the properties of any or all
the controls that exist in any given section?

Thanks,

Tim



Fri, 04 May 2001 03:00:00 GMT  
 Class object question -- looping through controls
As far as I can see, mDetail is not a collection of label controls, so it's
not meaningful to use
        for each lbl in mDetail

You could try
        dim ctl as control
        for each ctl in mDetail.controls
                if typeof ctl is label then
                        .
                        .
                        .
                endif
        next

HTH
        - Turtle



Quote:
> Here's what I got...

> I've created a class (clsSmoothForms) that has a label and a section
> property.  The labels work fine (I use the mouse move, up, and down
> events) from the client form.  I also would like to use the section
> events to loop through the labels in that section, but it keeps giving
> me the "object does not support this property or method" error message
> when the event I'm using executes. Here's the code I'm using for the
> section:

> '    *** Code Start ***
> Private WithEvents mDetail As Section
> _______________________________________

> Public Property Set Section(ByVal secNewDetail As Section)
>     Set mDetail = secNewDetail
> End Property
> _______________________________________

> Private Sub mDetail_MouseMove(Button As Integer, Shift As Integer, X As
> Single, Y As Single)
>     Dim lbl As Label     ' I only want to mess with the labels

>     For Each lbl In mDetail    ' Error happens here
>         debug.Print lbl.Name
>         lbl.Caption = "Changed" & lbl.Caption
>     Next
> End Sub

> Then, in the client form that will instantiate the class, I have this
> code...

> Dim cSEC1 As clsSmoothForms
> _______________________________________

> Private Sub Form_Load()
>     Set cSEC1 = New clsSmoothForms

>     Set cSEC1.Section = Me.Detail
> End Sub
> _______________________________________

> Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As
> Single, Y As Single)
> End Sub
> _______________________________________

> '    *** Code End ***

> Is it possible to get the names or modify the properties of any or all
> the controls that exist in any given section?

> Thanks,

> Tim



Fri, 04 May 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Object Class referring to other object class ??

2. Loop controls on container object

3. Loop controls on container object

4. Problems when looping through controls on form object, works in vb5 not vb6

5. Class/Object model design question

6. VB6-SOAP-WEBSERVICE Question: Receiving an object of a class defined in the webservice

7. A Question about objects and classes...

8. Class Object in VB5 Question

9. Class of control was not a loaded control class - Reference Replaced with unknown .OCA file

10. DBGrid Control Questions and general Data Object Questions

11. Objects, Classes and Controls HELP!

12. HELP:Accessing a class object in another class!

 

 
Powered by phpBB® Forum Software