Applies To:
  • CitectSCADA

I have tried every possible combination of formats to get Citect to pass variable tags and constants to a function using TaskNew but I still cannot get it to work right. Can someone explain to me in detail the format needed? 

This is a common problem and to be honest every time someone asks this question it takes some time to remember how it works so I will try to explain it clearer in this KB article.

The best way to look at it is to think of the list of arguments as a string and build the string up with code.

For instance lets say I have a function that I want to call with TaskNew and that function has 4 arguments that will be passed to it. The function name is MyFunction and the argument datatypes are INT, INT, REAL, and STRING in that order, i.e.. MyFunction(INT iVal1, INT iVal2, REAL rVal1, STRING sVal1).

Lets say the first argument is a constant (the number 6) and the remainding 3 are variable tags (INT_Tag1, REAL_Tag1, and STRING_Tag1 respectively).

There are really two ways to do do this. The first is the short way and the second is longer and does the same thing as the first but it may be easier to understand.

TaskNew("MyFunction","6," + INT_Tag1:### + "," + REAL_Tag1:####.#### + ",^"" + STRING_Tag1 + "^" ",0)

TaskNew("MyFunction","6," + IntToStr(INT_Tag1) + "," + RealToStr(REAL_Tag1,9,4) + ",^"" + STRING_Tag1 + "^" ",0)

As you see above INT_Tag1 and REAL_Tag1 have to be converted to strings first and then appended to the argument string. In the first one, the formating of the tag ( i.e.. :###) automatically converts the value into a string thus you can just append it to the argument string. STRING_Tag1 has to be passed to the function as a string so you basically have a string within a string. To do this the string needs to be between a pair of ^". All the plus signs (+) are doing are concatenating the string together. You need to look at each argument, get it into a string datatype, concatenate the commas into the string, and if you have a string to pass to the function you need to surround it with ^"s.

Note if you look at the example in the online help:


You noticed that the last argument iTwo:## does not have any quote or anything after it. That's because the format has converted it to a string already and there is no need to terminate the string. In my example above I needed a closing quote because of the string within a string needing the ^" to be pass to the function.