|
-
Aug 15th, 2003, 12:56 AM
#1
Thread Starter
New Member
Execute code at runtime
Does VB.net allow for a way of executing a string of code at runtime?
I've seen code using System.CodeDom.Compiler but it needs to compile an entire VB object and run it seperatley from the program. I just need to execute one line. (I have seen vb6 code that does this but that was 2 years ago)
Basically i'm trying to grab a form name from a database and display the form.
Thanks in advance.
-
Aug 18th, 2003, 04:16 PM
#2
Lively Member
Re: Execute code at runtime
Does VB.net allow for a way of executing a string of code at runtime?
Basically i'm trying to grab a form name from a database and display the form.
Sure!
You can do this using Reflection.
It does not compile a thing, just retrieve informations about objects and methods into assemblies and let you call them at runtime.
Take a look to this example:
VB Code:
Assembly a = Assembly.Load(strMyAssemblyFile);
Type oType = a.GetType(strCompleteNamespaceAndClassName);
object oMyObj = Activator.CreateInstance(oType);
MethodInfo oMethod = oType.GetMethod(strMethodName);
oMethod.Invoke(oMyObj, new object[] {MyParam});
Bye!
-
Aug 18th, 2003, 04:41 PM
#3
Frenzied Member
If the forms are within his project not an external assembly he can simply use this:
VB Code:
Dim frm As Form = Activator.CreateInstance(Type.GetType("Namespace.FormName"))
frm.Show()
Where NameSpace.FormName is the full name of the form type he wants to use.
Last edited by Lunatic3; Aug 18th, 2003 at 05:24 PM.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Aug 18th, 2003, 05:23 PM
#4
Sleep mode
One API function can does this , it was a little challenging on VB6 forum , look it up there , you may find it .
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
|