Results 1 to 3 of 3

Thread: Pass a Label into a subroutine - [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Location
    Surrey, UK
    Posts
    163

    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:
    1. Private Sub CommandButton1_Click()
    2.  
    3.     checkItRed Label1
    4.  
    5. End Sub
    6.  
    7. Sub checkItRed(ObName As Label)
    8.    
    9.     ObName.BackColor = vbRed
    10.     Me.Repaint
    11.  
    12. 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.

  2. #2
    Hyperactive Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    476

    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:
    1. Private Sub CommandButton1_Click()
    2.  
    3.     checkItRed Label1
    4.  
    5. End Sub
    6.  
    7. Sub checkItRed(ObName As Label)
    8.    
    9.     ObName.BackColor = vbRed
    10.     Me.Repaint
    11.  
    12. 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:
    1. Call checkitRed(Form.Label1)

    Where 'Form' is the name of the form where label1 is located.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Location
    Surrey, UK
    Posts
    163

    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:
    1. Sub checkItRed(ObName As Object)
    2.    
    3.     ObName.BackColor = vbRed
    4.     Me.Repaint
    5.  
    6. 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
  •  



Click Here to Expand Forum to Full Width