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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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