Too tricky?

cd1001

New Member
Joined
Feb 20, 2010
Messages
13
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"):
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
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,214,875
Messages
6,122,042
Members
449,063
Latest member
ak94

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top