Solved

call function by name

Posted on 2006-06-21
4
255 Views
Last Modified: 2010-04-30
what i want is this:

when i type:
Execute "Clear 16777215"



this function should be called:

private sub Clear(lColor as long)
'some code
end sub


how can i do this without having to hard-code it, and without using the ms scriptcontrol ?

0
Comment
Question by:Mark_FreeSoftware
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 16954606
(Potentially stupid answer)

Call Clear(16777215)
0
 
LVL 13

Author Comment

by:Mark_FreeSoftware
ID: 16954709

i am trying to execute a string (notice the quotes " ")
not just to call a sub


when i follow your advice (assuming you "forgot" the quotes)
i should use this sub:

Public Sub Execute(str As String)
   Call str
End Sub

that doesnt work....
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 16955059
Assuming your sub/function is Public and is in the Form (it can't be in a Module):

Option Explicit

Private Sub Command1_Click()
    Dim statement As String
    Dim vals As Variant
    Dim procName As String
    Dim parameter As Long
       
    statement = "Clear 16777215"
    vals = Split(statement, " ")
   
    procName = CStr(vals(0))
    parameter = CLng(vals(1))
   
    CallByName Me, procName, VbMethod, parameter
End Sub

Public Sub Clear(lColor As Long)
    Debug.Print lColor
End Sub
0
 
LVL 13

Author Comment

by:Mark_FreeSoftware
ID: 16955123

that is really awesome!
thank you so much!!!!


i have been searching this function for ages!





// when you don't know where to search, the internet is really too big
however when you have a start, it can't be big enough!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question