A surprise after 18 years of WinCC OA

An off-topic general discussion forum to chat about ANYTHING!
Search

Post Reply
2 posts • Page 1 of 1
User avatar
fmulder
Posts: 320
Joined: Wed Feb 03, 2010 9:46 am

A surprise after 18 years of WinCC OA

Post by fmulder »

One of the nice things of OA is the possibility to play with data types. Assign an int to a string, an int to string etc.. It is often quite usefull that you do not really think about data types and just assign them as you wish.

I'm sure (or at least I hope so ) that you all, at some time, have assigned a string to a boolean. Example:

* You read a value 'false' from a file or database
* and then just assign it to a boolean

Code: Select all

string conditionFromFile = FileRead( ... )
bool bCondition = conditionFromFile ;
Todat, one of my colleagues types the magic word 'False' in a database with an effect that suprised me. I then wrote the following small script to demonstrate.

Code: Select all

main()
{
  DebugN( "False -> " + (bool)"False" );
  DebugN( "false -> " + (bool)"false" );
  DebugN( "True -> " + (bool)"True" );
  DebugN( "true -> " + (bool)"true" );
}   
The result in the LogViewer ?

Code: Select all

WCCOAui1:["False -> TRUE"]     <== !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
WCCOAui1:["false -> FALSE"]
WCCOAui1:["True -> TRUE"]
WCCOAui1:["true -> TRUE"]
I can't this a bug because we all know that I should have checked the string. Still, I've assigned string to integers, floats and booleans for years and never realised this behavior

Hope it helps someone

share the fun
Frenk Mulder

User avatar
kilianvp
Posts: 422
Joined: Fri Jan 16, 2015 10:29 am

Re: A surprise after 18 years of WinCC OA

Post by kilianvp »

Casting "FALSE" or "false" work as expected. Everything else has always been true. Just do strtolower or strtoupper. It's similar in other languages! I did my Tests in 3.12 and 3.18

Code: Select all

main()
{
  // works as intended
  DebugN( "0 -> " + (bool)"0" );
  DebugN( "1 -> " + (bool)"1" );
  DebugN( "false -> " + (bool)"false" );
  DebugN( "FALSE -> " + (bool)"FALSE" );
  DebugN( "true -> " + (bool)"true" );
  // always true
  DebugN( "3 -> " + (bool)"3" );
  DebugN( "False -> " + (bool)"False" );
  DebugN( "True -> " + (bool)"True" );
  DebugN( "winccoa -> " + (bool)"winccoa" );
}

Code: Select all

WCCOAui0:["0 -> FALSE"]
WCCOAui0:["1 -> TRUE"]
WCCOAui0:["false -> FALSE"]
WCCOAui0:["FALSE -> FALSE"]
WCCOAui0:["true -> TRUE"]
WCCOAui0:["3 -> TRUE"]
WCCOAui0:["False -> TRUE"]
WCCOAui0:["True -> TRUE"]
WCCOAui0:["winccoa -> TRUE"]

Post Reply
2 posts • Page 1 of 1