Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


osirisja
2014-06-17T10:47:18Z
Hi all

I'm beginning to get a little more adventurous with the .NET Execute task and .NET code 😁. Can anyone give any simple examples of how VC Uservars can be passed as parameters or inline to the .NET code, and subsequently returned back to subsequent VC tasks?

Many thanks

Andy
Sponsor
Forum information
ErikC
2014-06-17T12:34:14Z
Hi Andy,

To use Uservars in your .NET task, you have to pass them to your method.

Like:

 public static string HelloWorld(string YourName)
 {
    return "Hello " + YourName;   
 }

Compile and refreh the methods and select HelloWorld.
After that you see a parameter window below (enlage the window a bit)
In there you can fill the YourName variable with a UserVariable or with a visualcron variable or a static value.

What will be returned here is usable as a visualcron variable task output in other tasks.

Regards,
Erik
Uses Visualcron since 2006.
osirisja
2014-06-17T13:21:37Z
Thanks Erik once again - I think I got it :-)

I just extended the previous XML Sort .Net code you kindly posted last week. For anyone else who is interested, this is what I have defined:



using System;
using System.Linq;
using System.Xml.Linq;
  
public class XMLsort
{
 /*  define variables netMyfile and netOutFile as parameters */
 /*  passed into the SORT method                             */ 
 public static void Sort(string netMyFile, string netOutFile)
 {
  /* open XML from netMyFile parameter value set as {UserVar(infile)}*/ 
    XElement root = XElement.Load(netMyFile);
    var orderedtabs = root.Elements("ROW")
        .OrderByDescending(xtab => (string)xtab.Element("INVESTOR").Element("PORTFOLIONUM"))
        .ToArray();
    root.RemoveAll();
    foreach (XElement tab in orderedtabs)
        root.Add(tab);
  /* write Sorted XML to netOutFile parameter value set as {UserVar(outfile)}*/        
    root.Save(netOutFile);
 }
} 



Great help on this forum guys

Cheers

Andy
Scroll to Top