Hello,
I'm struggling for a while with a generic mechanism to assign some short-cuts to methods that are implemented in classes. This is what I have so far:
In a class module ("test2"):
In a standard module:
I appreciate your help. Thank you very much.
Chris
I'm struggling for a while with a generic mechanism to assign some short-cuts to methods that are implemented in classes. This is what I have so far:
In a class module ("test2"):
Code:
Private Sub Class_Initialize()
Dim var(0 To 1) As Variant
var(0) = 5
var(1) = "ThisIsAstring"
AppOnKeyInClass "^{DOWN}", Me, "CallMeNow", VbMethod, var
End Sub
Public Sub CallMeNow(p_int As Integer, p_str As String)
MsgBox p_int & " " & p_str
End Sub
In a standard module:
Code:
Option Explicit
Public g_clsObject As Object 'Holds a reference to our class
Sub AppOnKeyInClass(ByVal p_strKey As String, ByRef p_clsObject As Object, p_strMethod As String, p_vbCallType As VbCallType, Optional p_varArrArgs As Variant)
Dim k As Long
Dim strExecute As String
Set g_clsObject = p_clsObject
For k = LBound(p_varArrArgs) To UBound(p_varArrArgs)
If TypeName(p_varArrArgs(k)) = "String" Then
p_varArrArgs(k) = Chr(34) & Chr(34) & p_varArrArgs(k) & Chr(34) & Chr(34) 'Have I to put some extra Quotes in there?
End If
Next k
Select Case UBound(p_varArrArgs) 'Select the cases for die Paramarray-Arguments
Case 0
'to implement
Case 1
strExecute = Chr(34) & "'CallByName " & "g_clsObject" & ", " & Chr(34) & Chr(34) & p_strMethod & Chr(34) & Chr(34) & ", " & p_vbCallType & ", " & (p_varArrArgs(0)) & ", " & (p_varArrArgs(1)) & "'" & Chr(34) 'Here is where the trouble is
Case 2
'to implement
Case 3
'to implement
Case 4
'to implement
End Select
Application.OnKey p_strKey, Evaluate(strExecute) 'Sadly it doesnt work
' Any Idea?
End Sub
'**********
Sub Test()
Dim cls As cTest2
Set cls = New cTest2
End Sub
I appreciate your help. Thank you very much.
Chris