Pass a Label into a subroutine - [RESOLVED]
Hi,
I am trying to make a series of labels change to a colour when you press a button.
This is what I have written:
VB Code:
Private Sub CommandButton1_Click()
checkItRed Label1
End Sub
Sub checkItRed(ObName As Label)
ObName.BackColor = vbRed
Me.Repaint
End Sub
Basically a label on the form called Label1 and when I click the command1 button I want the label to change to red.
But I want to have it as a seperate subroutine that needs to be called.
Can you see what I am doing wrong ? Claims there is a "Type Mismatch"
Re: Pass a Label into a subroutine
Quote:
Originally Posted by strobinson1
Hi,
I am trying to make a series of labels change to a colour when you press a button.
This is what I have written:
VB Code:
Private Sub CommandButton1_Click()
checkItRed Label1
End Sub
Sub checkItRed(ObName As Label)
ObName.BackColor = vbRed
Me.Repaint
End Sub
Basically a label on the form called Label1 and when I click the command1 button I want the label to change to red.
But I want to have it as a seperate subroutine that needs to be called.
Can you see what I am doing wrong ? Claims there is a "Type Mismatch"
When you call the checkitRed sub you need to write it this way:
VB Code:
Call checkitRed(Form.Label1)
Where 'Form' is the name of the form where label1 is located.
Re: Pass a Label into a subroutine
Yeah, That what I thought would have worked. but doesn't !!
Have solved it now by changing the argument to an Object:
VB Code:
Sub checkItRed(ObName As Object)
ObName.BackColor = vbRed
Me.Repaint
End Sub
and that worked !
Cheers :)