Results 1 to 5 of 5

Thread: Passing controls to functions

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    UK
    Posts
    36

    Question

    Does anyone know if :

    1. You can pass controls through to functions and change their properties.
    2. How to do it!

    Cheers Guys...

  2. #2
    Addicted Member darrenl's Avatar
    Join Date
    Jul 2000
    Location
    Portsmouth, UK
    Posts
    148
    O.K.

    The simplist way of doing this is to have a parameter in you function that is of type OBJECT. Say you have a control on your form, such as TEXT1, and a function called ChangeText that you want to alter the text property of the control. This example calls the function in the Form_Load event.

    Sub Form_Load()
    dim boolResult as Boolean
    boolResult = ChangeText(TEXT1)
    end sub

    Public Function ChangeText(TextControl as Object) as Boolean
    TextControl.Text = "My New Text"
    ChangeText = True
    End Function

    Dazzer

  3. #3
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    use TypeName to check of the Object passed is a TextBox
    i.e.

    if TypeName(Object)="TextBox" then
    ...
    end if



    td.


    "One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig


    [email protected]

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

  4. #4
    Guest
    You can also specify the type as Control.
    Code:
    Sub Change(ctl As Control)
        If TypeOf ctl Is TextBox Then ctl = "HELLO"
    End Sub

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    UK
    Posts
    36

    Cool Cheers Guys

    Cheers fellas that has got me sorted!

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