|
-
Oct 25th, 2006, 08:25 AM
#1
Thread Starter
Addicted Member
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"
Last edited by strobinson1; Oct 25th, 2006 at 09:20 AM.
-
Oct 25th, 2006, 09:07 AM
#2
Hyperactive Member
Re: Pass a Label into a subroutine
 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.
-
Oct 25th, 2006, 09:19 AM
#3
Thread Starter
Addicted Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|