Need Help With Class Module

J

JBNewsGroup

Hi



I have a question regarding Class Modules.



In my UserForm I created a collection of labels as:



Private colShapeControls AS Collection

.....

.....

Set ShapeLabel = fraShapes.Add("Forms.Label.1", "lbl" & ShapeName)



With ShapeLabel

.Left = ShapeLeft

.Top = ShapeTop

.Height = 20

.Width = 20

.Caption = ""

.Picture = LoadPicture(ShapePath & ShapeName & ".bmp")

.PicturePosition = fmPicturePositionRightCenter

.Tag = "lbl" & ShapeName

End With


Set cShapeSelect = New clsShapeSelect

Set cShapeSelect.mShapeSelectNew = ShapeLabel

colShapeControls.Add cShapeSelect, Cstr(ShapeId)

.....

.....



The Class Module code is:



Option Explicit



Public WithEvents mShapeSelectNew As MSForms.Label



Private Sub mShapeSelectNew_Click()

With mShapeSelectNew

.BackColor = vbYellow

.SpecialEffect = fmSpecialEffectSunken

End With

End Sub



I need help, or a suggestion, of how to determine the previous label
selected. I am trying to make the labels in the collection mutually
exclusive. If the user selected a label, then selected a different one, I
want to set the previously selected label to its initial state (vbButtonFace
and fmSpecialEffectFlat).



Thanks in advance for any help, and/or suggestions.



Jerry Bodoff
 
J

Jonathan West

Hi Jerry

To be able to return the prebious lavel selected, you would do something
like this

above the first routine in the class module, include the following

Private moShapeLast As MSForms.Label
Private moShapeCurrent As MSForms.Label

Then add the following to the

Then, add the following to the Sub mShapeSelectNew_Click routine

Set mShapeLast = mShapeCurrent
Set mShapeCurrent = mShapeSelectNew

Then you can expose the previous label as a property of the classs, like
this

Property Get LastShape() as MSForms.Label
Set LastShape = mShapeLast
End Property
 
J

Jerry Bodoff

Hi Jonathan,

I tried what you suggested but no cigar. None of the previous information is
saved. It seems that each time a label is "clicked" a new instance of the
class module is invoked and any information from the previous label is not
retained. It is not "elegant" but is there any way I can interrogate the
Collections array to do what I want or just bite the bullet and code 16
"click" events and a sub?

Previously I asked a similar question and I am using the "container" method
that worked in that project. However, there I did not have to reset a
previous selection, just insert document text.

As an aside, I am replying via the web. Is there any parameters that I have
to set up in Outlook Express to not have my text double-space? Since the new
web format I am using Outlook Express as the news reader and everything I
type is double spaced, or more.

I really appreciate your help with this. Thanks a lot.

Jerry Bodoff
 
J

Jonathan West

Rereading your original question again more carefully, it seems that you
want all the labels to be flat except for the currently selected one which
should be yellow & sunken.

If that is the case, then all you need to do on receiving a Click event is
to set *all* the labels to be flat, and then change the settings of just the
selected one.

You can iterate through all the labels in a UserForm like this, before
setting the one you want to be yellow and sunken.

Private Sub mShapeSelectNew_Click()

Dim oControl as Control
For Each oControl in mShapeSelectNew.Parent.Controls
If TypeOf oControl is MSForms.Label Then
oControl.BackColor = vbButtonFace
oControl.SpecialEffect = fmSpecialEffectFlat
End If
Next oControl
With mShapeSelectNew
.BackColor = vbYellow
.SpecialEffect = fmSpecialEffectSunken
End With
End Sub
 
J

Jerry Bodoff

Hi Jonathan,

Fantastic! It works like a charm. I was having trouble because I never used
the "Parent" property before and I did not know how to get to all the labels.
I learned something new.

I will post my Outlook question in the Outlook news group. Using the web and
having to sign in to Passport is a real pain. Besides which, the web page
text is too small. I really liked the old way (I think it was more "user
friendly").

Thanks for all your help. I really appreciated it.

Jerry Bodoff
 
J

Jonathan West

Jerry Bodoff said:
Hi Jonathan,

Fantastic! It works like a charm. I was having trouble because I never
used
the "Parent" property before and I did not know how to get to all the
labels.
I learned something new.

I will post my Outlook question in the Outlook news group. Using the web
and
having to sign in to Passport is a real pain. Besides which, the web page
text is too small. I really liked the old way (I think it was more "user
friendly").

Make sure you post to an Outlook Express group rather than an Outlook group.
They are two completely different programs, and Outlook does not do news.

Also, this website may be helpfil to you: http://insideoe.tomsterdam.com/
 
J

JBNewsGroup

Hi Jonathan,

Last post in this thread.

I finally got Outlook Express fixed, was set for sending HTML and not plain
text.

Regarding sending the clicked label data to the macro. I created 2 Property
Set's for setting a pointer to a dummy hidden label on the user form and to
set a pointer to an control which is to receive focus after clicking a
label. The class module copies the relevant clicked label data to the form
hidden label and then sets focus to the defined control. It works great.

Thanks for all your help.

Jerry Bodoff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top