-
August 19th, 2002, 11:38 PM
#1
Execute function as string
Hi buddies.
I have a little problem.I want to execute a function(defined by me)
as a string.
Acctually I have given function name nad parameter in .INI file.parameters may be field of a table in database.So by fetching all information from .INI file and database n\and after concatenating I got whole function string now I want to execute
this.
Regards
Yujvendra
-
August 20th, 2002, 01:12 AM
#2
Take a look at the CallByName function.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
August 20th, 2002, 01:50 AM
#3
Reply
Hi buddy.
Thanx for response.
But CallbyName works for function of some object not for simple user defined function.If u find some way pls. response me.
Regards
Yujvendra
-
August 20th, 2002, 02:41 AM
#4
Play with this
Code:
Option Explicit
'add a reference to microsoft script control
'yes, they call it a control, but you can add a reference to it
'via menu->project->references
Private myScript As ScriptControl
Private Sub Form_Load()
Set myScript = New ScriptControl
'you need to tell it you want to use vbscript
'and not microsoft Jscript
myScript.Language = "Vbscript"
'add your sub or your function
'remember you DO NOT have the "private"
'or "public" statement here
'do not forget you do not have data type also,
'but only variant variables
'(but you can use Cstr, Cdbl, Cbool and so on
'if you need)
myScript.AddCode "sub showmyMessage" & vbCrLf & "MsgBox ""Ehy, does this really works?"" " & vbCrLf & "end sub"
'Now run the added sub or function:
myScript.Run "showmyMessage"
Set myScript = Nothing
End Sub
By the way: did you already vote?? (see below, red lines)
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
August 20th, 2002, 08:04 AM
#5
The CallByName function works with Any function, including your own.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
August 20th, 2002, 08:10 AM
#6
Marketing our skills - please participate in the survey and share your insights
-
-
March 11th, 2003, 12:02 PM
#7
Nearly There . . .
Cheers Cimperiali
I have adapted that code but get error 424
Object required: 'DataReportEEList'
The code now looks like ;
Private Sub ScriptReport(RepName As String)
Set myScript = New ScriptControl
myScript.Language = "Vbscript"
myScript.AddCode "Sub ShowReport" & vbCrLf & RepName & ".Show 1" & vbCrLf & "End Sub"
'Now run the added sub or function:
myScript.Run "ShowReport"
Set myScript = Nothing
End Sub
What am I doing wrong ? the report is in the project and the name is the same ?
-
March 11th, 2003, 11:47 PM
#8
Hi Cimperiali
I tried your code, and it worked well.
But when I tried changing the procedure to a function which takes parameters, I encountered an error like - "Object does not support this property or method", or so
Suhaib
-
March 11th, 2003, 11:53 PM
#9
GOT IT MYSELF !!
works something like this .....
myScript.run "myfunction", <param1>, <param2>, ...... <paramn>
Thanks
Suhaib
-
March 11th, 2003, 11:57 PM
#10
But Signor ...
How do you hold the values returned by this funtion ???
Suhaib
-
March 12th, 2003, 12:05 AM
#11
Suhaib,
The run method automatically returns the value from the function
Busy
-
March 12th, 2003, 12:13 AM
#12
Judgey,
If you want to access an object (say a form) inside the script try to add it first by issuing the AddObject method
s.AddObject "MyForm", Form1
Busy
-
March 12th, 2003, 12:13 AM
#13
Thread1
Could you tell me how I can store this return value to a variable and display it ?
Suhaib
-
March 12th, 2003, 12:21 AM
#14
Suhaib,
myScript.AddCode "function hello(byval name)" & vbCrLf & "hello = ""hello "" & name" & vbCrLf & "end function" & vbCrLf
varRet = myScript.run("hello", "Suhaib")
MsgBox varRet
Got it?
Busy
-
March 12th, 2003, 12:31 AM
#15
The vba.CallByName is applicable too for methods (sub/func) within the object. The object can be a form.
Busy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|