How do I pass many parameters from VB.Net to a macro?

Correct, ui.vision can send only cmd_var1, cmd_var2 and cmd_var3. These variable names are fixed.

But as @newuserkantu mentioned, there is a good workaround. You can combine all your 10+ values into one long string, and then, inside the macro, split the string into its part again:

In the macro below I show how it is done. Assume !cmd_var1 would contain this string:

aaaaaaXXX111\n\bbbbXXX1 2 3 4 5XXXChinese你好XXXLong text: The Send-MailMessage cmdlet uses the From parameter to specify the message’s sender. The To parameter specifies the message’s recipient. The Subject parameter uses the text string Test mail as the message because the optional Body parameter is not includedXXXthis works.

and then inside the macro split the string at XXX. So now the array (“a” in the macro below) contains the separate values.

You can now use e. g. forEach to loop over this array, or get your values with the [x] array notation:

  • echo | Value1 is ${a[0]}
  • echo | Value2 is ${a[1]}
  • echo | Value30 would be in ${a[29]}

Result:

split string

Macro:

{
  "Name": "split string",
  "CreationDate": "2023-2-7",
  "Commands": [
    {
      "Command": "store",
      "Target": "aaaaaaXXX111\\n\\bbbbXXX1 2 3 4 5XXXChinese你好XXXLong text: The Send-MailMessage cmdlet uses the From parameter to specify the message's sender. The To parameter specifies the message's recipient. The Subject parameter uses the text string Test mail as the message because the optional Body parameter is not includedXXXthis works.",
      "Value": "var1",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "s = ${var1}; myArray = s.split(\"XXX\"); return myArray;",
      "Value": "a",
      "Description": ""
    },
    {
      "Command": "forEach",
      "Target": "a",
      "Value": "value",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Value is: ${value}",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "comment",
      "Target": "You can also access the array values this way:",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Value1 = ${a[0]}",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Value2 = ${a[1]}",
      "Value": "pink",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Value3 = ${a[2]}",
      "Value": "brown",
      "Description": ""
    }
  ]
}
3 Likes