Results 1 to 2 of 2

Thread: how to examine if an object has a method in realtime?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    81

    how to examine if an object has a method in realtime?

    I use CallByName fuction:

    if something??? then
    CallByName Me, strMethodName, VbMethod,
    end if

    but sometimes the "strMethodName" method doesnt exist and this cause runtime error. can I examine that before calling CallByName?

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: how to examine if an object has a method in realtime?

    VB Code:
    1. Private Sub Form_Load()
    2.     MsgBox HasProperty(Form1, "Caption")
    3.     Unload Me
    4. End Sub
    5.  
    6. Public Function HasProperty(objObject As Object, strProperty As String) As Boolean
    7.     Dim varRet As Variant
    8.     On Error Resume Next
    9.     varRet = CallByName(objObject, strProperty, VbGet)
    10.     If Err.Number = 0 Then
    11.         HasProperty = True
    12.     End If
    13.     On Error GoTo 0
    14. End Function



    Has someone helped you? Then you can Rate their helpful post.

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