Results 1 to 2 of 2

Thread: Method of calling an API?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Norway
    Posts
    112
    I want to use the CallByName function that comes with VB6. I've got VB5 and I have the Msvbvm60.dll that belongs to VB6.
    I've declared the rtcBeep() and it works fine (was just a test).

    Problem is to declare the
    rtcCallByName(control, function, indata to the function)
    (the last - indata - is probably a ParamArray)

    Anyone know how to declare it? Is it just to declare as it is in VB6? If so, anyone got the exact declaration?

  2. #2
    Guest
    Sraight outta MSDN:

    HOWTO: Use the CallByName Function to Run a Procedure
    ID: Q186143



    --------------------------------------------------------------------------------
    The information in this article applies to:

    Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 6.0

    --------------------------------------------------------------------------------


    SUMMARY
    The CallByName function provides Visual Basic 6.0 with the ability to call a property or method of an object using a string at run-time. Unlike the previous versions of Visual Basic in which methods and properties had to be known at design-time, the CallByName function allows for a great deal of flexibility at run-time. The use of this function is limited to OLE servers and Visual Basic class modules.



    MORE INFORMATION
    The following sample demonstrates how to use the CallByName function to call a method, a Property Let, and a Property Get. For more information on the CallByName function, please refer to the Visual Basic Help Files and the Books On-Line.


    Steps to Create Sample Project
    Start a new Standard EXE project in Visual Basic. Form1 is created by default.


    Add a Class Module (Class1) to the project.


    Add the following code to the Class Module:

    Option Explicit
    Private MyPropValue As Integer

    Public Function Multiply(x As Integer, y As Integer) As Integer
    Multiply = x * y
    End Function

    Public Property Get MyProperty() As Variant
    MyProperty = MyPropValue
    End Property

    Public Property Let MyProperty(ByVal vNewValue As Variant)
    MyPropValue = vNewValue
    End Property




    Add the following code to the Form Module (Form1):

    Option Explicit
    Private Sub Form_Click()
    Dim myclass As New Class1
    Dim sum As Integer
    Dim prop As Integer

    ' Example of calling a method with CallByName
    ' equivalent to -- sum = myclass.Multiply(12, 12)
    sum = CallByName(myclass, "Multiply", VbMethod, 12, 12)
    MsgBox sum

    ' Example of a property let with CallByName
    ' equivalent to -- myclass.MyProperty = 5
    CallByName myclass, "MyProperty", VbLet, 5

    ' Example of a property get with CallByName
    ' equivalent to -- prop = myclass.MyProperty
    prop = CallByName(myclass, "MyProperty", VbGet)
    MsgBox prop
    End Sub




    Run the Project and click on Form1. A message box displaying the number 144 and a message box displaying the number 5 are shown in succession.



    Additional query words: kbDSupport kbDSD kbVBA kbVBp600 kbVBp


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