<?>..this does it's thing...
Code:
Option Explicit
Private WithEvents lbl1 As Label
Private Sub Form_Load()
Set lbl1 = Controls.Add("VB.label", "lbl1")
With lbl1
.Left = 240
.Top = 100
.Width = 244
.Height = 80
.BackColor = vbWhite
.Visible = True
End With
End Sub
Private Sub Command1_Click()
Randomize
If lbl1.Visible = True Then
With lbl1
.Left = 240
.Top = 100
.Width = 1000
.Height = 500
.Caption = Int(Rnd * 9)
.Visible = True
End With
Else
Set lbl1 = Controls.Add("VB.label", "lbl1")
End If
End Sub
<?>..this checks for it then creates it if not there
'beat this thing up a little more
'now I think it is more of what you wanted..
Code:
Option Explicit
Private WithEvents lbl1 As Label
Public sExists As Boolean
'
Public Sub CheckMe()
'
'check to see it the form has a lbl1 on it.
'if it is there make it visible and if
'it's not there create it
'mycontrol = control and increment is increment for forms
'some situtations use more than one form.
'
Dim ctlMyControl As Control
Dim intIncrement As Integer
sExists = True
'
For intIncrement = 0 To Forms.Count - 1
For Each ctlMyControl In Forms(intIncrement).Controls
'
If TypeOf ctlMyControl Is Label Then
'
If ctlMyControl.Name = lbl1 Then
sExists = False
Exit Sub
End If
End If
'
Next ctlMyControl
'
Next intIncrement
End Sub
Public Sub MakeLabel()
'if not label make one
Set lbl1 = Controls.Add("VB.label", "lbl1")
With lbl1
.Left = 240
.Top = 100
.Width = 244
.Height = 80
.BackColor = vbWhite
.Visible = True
End With
'
End Sub
Private Sub Command1_Click()
Randomize
If sExists = False Then Call MakeLabel
Call CheckMe
If lbl1.Visible = True Then
With lbl1
.Left = 240
.Top = 100
.Width = 1000
.Height = 500
.Caption = Int(Rnd * 9)
.Visible = True
End With
End If
End Sub