Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Request some example codes on these new features
#1
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.
#2
Type/click CsScript or CsExec etc in the code editor and press F1.

Some examples copied from there:
Macro Macro2068
Code:
Copy      Help
;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")
#3
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.
#4
Copied from VbExec help:
Macro Macro2064
Code:
Copy      Help
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
Code:
Copy      Help
;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
Code:
Copy      Help
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.
#5
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.
#6
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").


Forum Jump:


Users browsing this thread: 1 Guest(s)