Posts: 25
Threads: 4
Joined: Oct 2010
Could I request some examples code on how to use the the features below?
Class CsScript, functions CsExec, CsFunc, VbExec, VbFunc. Compiles and executes C# or VB.NET code.
Just some simple examples would do.
Thanks.
Posts: 12,092
Threads: 142
Joined: Dec 2002
Type/click CsScript or CsExec etc in the code editor and press F1.
Some examples copied from there:
Macro
Macro2068
;Use CsExec to execute script containing function Main, like to run program compiled from this code.
str code=
;using System;
;public class Class1
;{
;;;;;static void Main(string[] a)
;;;;;{
;;;;;;;;;int i;
;;;;;;;;;for(i=0; i<a.Length; i++) Console.Write(a[i]);
;;;;;}
;}
CsExec code "called Main"
;__________________________________________________
;Use CsFunc to call single static function once.
str code2=
;using System;
;public class Class1
;{
;;;;;static public string StaticFunc(string s)
;;;;;{
;;;;;;;;;Console.Write(s);
;;;;;;;;;return "something";
;;;;;}
;}
str R=CsFunc(code2 "called StaticFunc using CsFunc")
out R
;__________________________________________________
;Use CsScript class when want to call multiple functions, create objects, set options, call functions faster, create or load .dll or .exe files.
str code3=
;using System;
;public class Class1
;{
;;;;;static public string StaticFunc(string s)
;;;;;{
;;;;;;;;;Console.Write(s);
;;;;;;;;;return "something";
;;;;;}
;;;;;public int Func1(int a, int b)
;;;;;{
;;;;;;;;;return a+b;
;;;;;}
;;;;;public string Func2(string a, string b)
;;;;;{
;;;;;;;;;return a+b;
;;;;;}
;}
CsScript x.AddCode(code3)
;call static function
str R2=x.Call("Class1.StaticFunc" "called StaticFunc using CsScript.Call")
;create object and call non-static function
IDispatch obj=x.CreateObject("Class1")
out obj.Func1(2 3)
out obj.Func2("2" "3")
Posts: 25
Threads: 4
Joined: Oct 2010
Thanks Gintaras but actually I wanted the examples in vb.net.
Can show me some examples using the above features in vb.net please?
Thank you
PS the current beta version info is 2.3.5.9, I think you type wrongly in your beta annoucement forum section.
Posts: 12,092
Threads: 142
Joined: Dec 2002
Copied from VbExec help:
Macro
Macro2064
VbExec ""
#ret
Imports System
Imports System.Windows.Forms
Module Module1
Sub Main()
;Console.WriteLine("VB")
;MessageBox.Show("VB")
End Sub
End Module
Copied from VbFunc help:
Macro
Macro2064
;example with code in string and using Module
str code=
;Imports System
;Public Module Test
;Function Add(a as Integer, b as Integer) As Integer
;;Return a+b
;End Function
;End Module
out VbFunc(code 5 2)
;example with code in same macro and using Class
out VbFunc("" 5 2)
#ret
Imports System
Public Class Test
Public Shared Function Add(a as Integer, b as Integer) As Integer
;Return a+b
End Function
End Class
Example using CsScript class:
Macro
Macro2064
CsScript x.SetOptions("language=VB")
x.AddCode(code)
;then use x.Call or x.CreateObject like with C#
_______________
Yes, must be 2.3.5.9. Thank you.
Posts: 25
Threads: 4
Joined: Oct 2010
Thank you.
Anything new on 2.3.6.4?
There isnt any information below
http://www.quickmacros.com/forum/viewtopic.php?t=5566
And also when running compiled Macro Macro2064 exe sample. A QM temp folder containing a dll is created and is left there even after running the exe file.
Does it mean that compiled exe files that contain either vb.net or C# functions will create such QM temp folder containing the dll, and even after finish running the exe file, the folder and dll is left behind? Couldn't the temp folder and dll cleanup itself(deleted) after running the exe file?
Thank you.
Posts: 12,092
Threads: 142
Joined: Dec 2002
In 2.3.6.3-4 - several bug fixes in Sqlite functions.
About temp files - read in CsScript Help. It's possible to avoid creating them: in exe use compiled assembly, or x.SetOptions("noFileCache=true").