Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

controls in a class object

Status
Not open for further replies.

meltdown

Programmer
May 1, 2002
7
0
0
CA
I am adding dynamic controls to a form using a class object.

in a form load section I have

Dim displayStandings As standings
Set displayStandings = New standings
Call displayStandings.setCurrentForm(frmMain)
Call displayStandings.setCurrentFrame(frameStandings)
Call displayStandings.buildStandings

The class is defined here :

Option Explicit

Dim WithEvents ctlLabel As VB.Label
Private currentForm As Form
Private currentFrame As Frame

Public Sub buildStandings()
Dim i As Integer

Dim x As Integer
x = 720
For i = 1 To 1
Set ctlLabel = currentForm.Controls.Add("VB.Label", "lblTestx" & i, currentFrame)
With ctlLabel
.AutoSize = True
.Move 2500, x, 1000, 1000
.Caption = "lblTestx222" & i
.Visible = True
.ForeColor = vbBlue
.FontUnderline = False
.MousePointer = vbDefault
End With
x = x + 240
Next i

End Sub

Public Sub setCurrentForm(ByRef newCurrentForm As Form)
Set currentForm = newCurrentForm
End Sub

Public Sub setCurrentFrame(ByRef newCurrentFrame As Frame)
Set currentFrame = newCurrentFrame
End Sub

Public Sub ctlLabel_Click()
MsgBox ("Clicked ")
End Sub

I can't get the clicked to show up. If I add all this code directly in the form I have no problem. I suspect that it is because since I am creating the control dynamically with events it needs to ne in the form directly.

Has anyone tried this. Any ideas. I need to have a way to make the standings section be independant of the form since I may have to use it on another form or frame.

Any help would be great.

thanks
 
Did you create the procedure:
[tt]
Public Sub ctlLabel_Click()
MsgBox ("Clicked ")
End Sub
[/tt]
manually by typing it into the IDE?

I would try having VB create the event procedure for you to make certain they are the same. From the left hand combo box at the top of the VB IDE, the name of your module level variable:
[tt]
Dim WithEvents ctlLabel As VB.Label
[/tt]
should be available. Selecting that name from the left hand combo box should allow you to select the available event procedures from the right hand combo box. Once you select the Click event from the right hand combo box, VB will create the code for the event procedure for you.

If the name is not available, there probably is something wrong with how the variable was declared or you have exceeded the limitations of how event procedures can be delegated in VB.
 
Try changing Public to Private
Private Sub ctlLabel_Click()
MsgBox ("Clicked ")
End Sub

The "signture" may not be matching up. This is a compile time thing. Better to set it up by clicking on the ctlLable definition in the combo-box and then selecting click.
Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top