Solved

call function by name

Posted on 2006-06-21
4
251 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
  • 2
4 Comments
 
LVL 65

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 85

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now