|
-
Jun 3rd, 2005, 05:41 PM
#1
Thread Starter
Fanatic Member
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
-
Jun 3rd, 2005, 05:47 PM
#2
-
Jun 3rd, 2005, 05:48 PM
#3
Re: CallbyName equivilent for VB5
You could do this.
VB Code:
Select Case rs!CNTRL_NME
Case "cmdClick"
Call cmdClick_Click
Case "txtHuh"
' Do something
' etc
End Select
-
Jun 3rd, 2005, 07:05 PM
#4
PowerPoster
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.
-
Jun 3rd, 2005, 10:10 PM
#5
Thread Starter
Fanatic Member
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.
-
Jun 4th, 2005, 05:15 PM
#6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|