Solved

call function by name

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 62
Windows 10 start screen issues 9 55
VBA filters 2 64
Crystal reports - Formula Field code need assistance with code 17 81
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 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