Technical FAQs

Ask a Question

How to compare two string variables in Vijeo Designer using scripting?

Goals and Symptoms

This Simple Resolution is to show customers how to write a script to compare two string variables.

Causes and Fixes

Below is a script to compare two string variables in Vijeo Designer:
String s1, s2; //declare two internal script string variables called s1 and s2
int mycompare; //declare integer variable mycompare
s1 = MyString01.getStringValue(); //let s1 equal to the external variable called MyString01
s2 = MyString02.getStringValue(); //let s2 equal to the external variable called MyString02
mycompare = s1.compareTo(s2); //compare the two strings, returns 0 if equal and anything else if not equal
if (mycompare == 0) //if statement to compare if mycompare is equal to 0
ResultString.write("String are equal"); //write a string constant to the external variable ResultString
else
ResultString.write("String are not equal"); //write a string constant to the external variable ResultString

Was this helpful?
What can we do to improve the information ?