Insert() and expression in value text box


Recommended Posts

Hi,

I am new to DAQFactory. In our project one of the task is to repeat water leakage status from Modbus to a remote LCD display via a serial link. We encounter a problem:

1. We need to construct a 101 characters string and then send it to the LCD. We use the function Insert() to append an 'A' for an leakage alarm and a 'X' for normal. Like this:

Global string Vehicle = "N"

					if (Alarm_1 >= 0)
						Vehicle = Insert(Vehicle,1,"A")
					else
						Vehicle = Insert(Vehicle,1,"A")				  
					endif

					if (Alarm_2 >= 0)
						Vehicle = Insert(Vehicle,2,"A")
					else
						Vehicle = Insert(Vehicle,2,"A")				  
					endif

					...............
					...............
					...............

					if (Alarm_100 >= 0)
						Vehicle = Insert(Vehicle,100,"A")
					else
						Vehicle = Insert(Vehicle,100,"A")				  
					endif

To monitor the result, we use a variable value and type Vehicle in the Expression, no unit and precision = 0.

Nothing happens.

2. To assure the insert() function is working, we type another sequence:

Global string New_Vehicle = "ABCDE"
				  Global string New_Vehicle1 = ""

				  New_Vehicle1 = Insert(New_Vehicle,3,"abc")

We use another variable value and type New_Vehicle1 in the Expression, no unit and precision = 0.

Nothing happens.

3. However, if we type directly Insert(New_Vehicle,3,"abc") in the Expression of variable value, we got:

ABCabcDE

It confuses us a lot. What thing we have done wrong?

Best Regards,

chanchungfat

Link to comment
Share on other sites

well, first you are not really inserting, but rather adding to the end of the string, so I don't think Insert() is the correct function to use. You can just use +, which concats two strings. Also, you can make the script a lot less painful by doing something like this:

Global string Vehicle = "N"

for (private i = 1, i < 101, i++)
   if (evaluate("Alarm_" + i + " >= 0"))
	  Vehicle += "A"
   else
	  Vehicle += "X"
   endif
endfor

or even better:

Global string Vehicle = "N"
for (private i = 1, i < 101, i++)
   Vehicle += iif(evaluate("Alarm_" + i + " >= 0"), "A", "X")
endfor

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.