Solved

call function by name

Posted on 2006-06-21
4
250 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 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

17 Experts available now in Live!

Get 1:1 Help Now