Results 1 to 6 of 6

Thread: CallbyName equivilent for VB5

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    CallbyName equivilent for VB5

    I've been beating myself up trying to figure this out. I also searched through the forum and didn't find anything that could help me with this. I have a table which holds the names of various controls on my form:

    ie
    rs!CNTRL_NME = "cmdClick"
    (cmdClick is the name of my button)

    If I can call rs!CNTRL_NME by name, then this would work great. Unfortunately, I'm not using VB6 which is where this was first introduced. Can someone provide me with an equivalent for VB5 which I can use to call the above recordset variable by name?

    Thanks in advance!

    Strick

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

    Re: CallbyName equivilent for VB5

    I think this worked for VB5 : Me.Controls(rs!CNTRL_NME).SomeProperty


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

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: CallbyName equivilent for VB5

    You could do this.

    VB Code:
    1. Select Case rs!CNTRL_NME
    2.     Case "cmdClick"
    3.         Call cmdClick_Click
    4.     Case "txtHuh"
    5.         ' Do something
    6.     ' etc
    7. End Select

  4. #4
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166

    Re: CallbyName equivilent for VB5

    Date: 4/19/2001
    Versions: VB5 VB6 Level: Intermediate
    Author: The VB2TheMax Team
    Thanks to the undocumented TlbInf32 library you can emulate the VB6
    CallByName() function in VB5 too. First, add a reference to the
    "TypeLib Information" type library in your project. This library contains
    the InvokeHook function, which is very similar to CallByName.

    Let's suppose you have an ActiveX DLL called MyServer.dll that exposes
    this function:

    ' Class.cls
    Public Function MyFunc (FirstParam, SecondParam) As String
    :
    End Function

    In VB6 you're able to call MyFunc() with:
    Dim obj As Object
    Dim First, Second
    Dim obj As Object
    Dim result As String

    ' create the object
    Set obj = CreateObject("MyServer.Class")
    ' call MyFunc
    result = CallByName(obj, "MyFunc", VbMethod, First, Second)

    The following code demonstrates how to do the same in VB5:
    Dim TLI As New TLIApplication
    Dim obj As Object
    Dim First, Second
    Dim obj As Object
    Dim result As String

    ' create the object
    Set obj = CreateObject("MyServer.Class")
    ' call MyFunc
    result = InvokeHook(obj, "MyFunc", INVOKE_FUNC, Second, First)

    The sintax of InvokeHook() is simple: the first parameter is the object
    which you want to work, the second one indicates the name of the
    property or method to call, the third parameter is the type of call
    being made and can be one of the following values:

    INVOKE_PROPERTYGET to assign a property value (vbGet in CallByName)
    INVOKE_PROPERTYPUT to retrieve a property value (vbLet in CallByName)
    INVOKE_PROPERTYPUTREF to assign an object reference to a property
    (vbSet in CallByName)
    INVOKE_FUNC for a sub or function call (vbMethod in CallByName)
    The last parameter is a ParamArray used to pass the list of parameters
    to the function being invoked: note that parameters must be in
    reverse order. Note that InvokeHook can be useful even under VB6,
    in that it lets you work around a bug of VB6's CallByName.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Re: CallbyName equivilent for VB5

    MANOVA, looks like this works well. Only problem I'm running into now is stringing together my recordset variables to form a complete statement.

    my goal:
    cmdClick.visible = True

    my recordset variables:
    rs!CNTRL_NME = cmdClick
    rs!CNTRL_PROP = .visible
    rs!CNTRL_ACCESS = true

    My code:
    Me.Controls(rs!CNTRL_NME) & rs!CNTRL_PROP = rs!CNTRL_ACCESS
    'Doesn't like the rs!CNTRL_PROP part. Will work fine if I use .visible in its place, but I need to take it from the variable.

    Thanks

    Strick
    Last edited by stricknyn; Jun 3rd, 2005 at 10:19 PM.

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

    Re: CallbyName equivilent for VB5

    You won't be able to do that this way... Try MartinLiss' or dw85745's solutions...


    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