Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String Interpolation
#1
Hello -

Does QM support String Interpolation (https://docs.microsoft.com/en-us/dotnet/...terpolated) when using C#?

I am trying the following code.
Code:
Copy      Help
#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>?
#2
No, QM2 uses older C# version, because Windows does not have the new C# compiler installed.
#3
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.
 
Code:
Copy      Help
 
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?
#4
call like this need two single quotes  for other arguments besides 1st.
Code:
Copy      Help
CsExec("" F"/SampleFunction ''{output}''")

for the MesssageBox use Composite formatting:
Code:
Copy      Help
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]);
,}
}
#5
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!  Big Grin

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?
#6
you can call the qm function from any other function or macro like so
Macro Macro one
Code:
Copy      Help
SampleFunction

read here for more info
Function tips (quickmacros.com)

and here
function (quickmacros.com)
#7
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.


Forum Jump:


Users browsing this thread: 1 Guest(s)