Solved

call function by name

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB error "Type mismatch" 2 53
SSRS expression Issue finding a string 10 76
Macro Excel - Multiple If conditions 2 71
Problem to With line 4 57
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

785 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