Posts: 3
Threads: 1
Joined: Dec 2020
Hello -
Does QM support String Interpolation (
https://docs.microsoft.com/en-us/dotnet/...terpolated) when using C#?
I am trying the following code.
#ret
//C# code
using System;
using System.Windows.Forms;
class SampleFunction
{
static void Main(string[] args)
{
MessageBox.Show($"Hello:{args[0]}");
}
}
And I get the following error.
<macro "Scripting_Link /45 19 2 ''Macro2''">Macro2(45,19): error CS1056: Unexpected character '$'. <help #IDP_ERR>?
Posts: 12,092
Threads: 142
Joined: Dec 2002
No, QM2 uses older C# version, because Windows does not have the new C# compiler installed.
Posts: 3
Threads: 1
Joined: Dec 2020
Thank You!
An additional question on using the C# side of things. I am trying to pass in some arguments but it looks like I have the syntax incorrect and cannot determine why.
str output
output.from("Customer:" cstname)
CsExec("" F"/SampleFunction" "{output}")
This is executing the code above and fails. What is incorrect in my syntax?
And finally, is there a way to call another function from my current macro? For example, I have a Macro named Macro one and a Function called SampleFunction that I want to use in multiple macros. How do I call the SampleMacro function that is not in the current macro?
Posts: 1,338
Threads: 61
Joined: Jul 2006
call like this need two single quotes for other arguments besides 1st.
CsExec("" F"/SampleFunction ''{output}''")
for the MesssageBox use Composite formatting:
str cstname ="Mark"
str output
output.from("Customer:" cstname)
CsExec("" F"/SampleFunction ''{output}''")
#ret
//C# code
using System;
using System.Windows.Forms;
class SampleFunction
{
,static void Main(string[] args)
,{
,,int i; for(i=0; i<args.Length; i++) Console.WriteLine(args[i]); //display in QM output
,,// Composite formatting:
,,MessageBox.Show(String.Format("Hello:{0}", args[1]));
,,Console.WriteLine("Hello:{0}", args[1]);
,}
}
Posts: 3
Threads: 1
Joined: Dec 2020
Quote:call like this need two single quotes for other arguments besides 1st.
This same solved what I needed for the follow-up question. Thank you!
Can anyone assist on how to call a function stored elsewhere. I have a folder called Functions and a function called SampleFunction (written in C#) that I want to call from multiple macros. How can I do such?
Posts: 1,338
Threads: 61
Joined: Jul 2006
you can call the qm function from any other function or macro like so
Macro
Macro one
read here for more info
Function tips (quickmacros.com)
and here
function (quickmacros.com)
Posts: 12,092
Threads: 142
Joined: Dec 2002
12-04-2020, 06:55 AM
(This post was last modified: 12-04-2020, 07:22 AM by Gintaras.)
Create new macro with this template: menu File / New / Templates /Scripting / Scripting C#, call various functions2.
In code click AddCode and press F1... You'll see, C# code can be anywhere.
Edit the x.AddCode("") line and delete code from #ret to the end. Or move the C# code to other macro etc. Also delete other example code you don't need.