0

What does this mean "Implicit Value Conversion"

Andy 1 month ago updated by Gustav Widén (System support) 1 month ago 5

Hey

I have a couple of channels in a project that tell me there is an implicit value conversion occurring. What I'm confused about is exactly what it means and why its a warning?

In the Qcode below:-

HydOilLowNCorNO is a digital parameter that determines whether the input condition is NC or NO which translates to if a logic 1 is good or bad.

MaintBypassSensorHydOilLow is a digital parameter that determines whether we should action the sensor inputs or simply ignore them. iI's used here in this channel and in an almost duplicate of the channel that deals with digital input HydOilLevelVeryLow which is the last switched step on the tank level sensor and which triggers an immediate idle down, and timed shutdown of engine 

The Qcode is:-

TempResult:=0
If HydOilLowNCorNO Then TempResult:=Not(HydOilLevelLow) else TempResult:=HydOilLevelLow
If MaintBypassSensorHydOilLow then TempResult:=0
Result:=TempResult

The warning I get is that the bolded underline is an implicit value type conversion. What I struggle to understand is what is being converted? everything except the local variable TempResult is digital including the channel type IDC. There as far as I know is no way to declare a variable as specifically type digital and if I change line 1 to TempResult:=False then I get another implicit value type conversion warning for that line.

I know a warning isn't the end of the world but what do I need to do to get rid of the warning or produce better code? Is there a way to declare the local variable TempResult as type digital that Im simply not aware of?

Warnings in IQAN Design  to me infer something is suboptimal but here I cant see what I should do to change that.

+1

Hi Andy,

Your are correct, IQAN is warning that using numeric values as boolean or boolean values as numeric is suboptimal as you put it.

Image 3372

Hi

I have same issue (Implicit Value Type Conversion) when I update a project from Design 6.06 to Design 6.08.

Then, in my case,  a lot IVTC warnings appear.

At Project Check component type 'Math Object' appear, but when I check it considers a IDC. See image below


Image 3373

Never the less the project is still functional as expected.

Ps. 

We did not use Design 6.07, we moved from 6.06 to 6.08

+1

Hi Tim,

Sorry, I did not read your comment in time, now I understand why.

Thanks

Ok lets take what is provided at face value "Using numeric values as Boolean, or boolean values as numeric should be avoided.......

I used numeric then I used the Qcode reserved words true and false. In both cases I got the same result. How else can one define a boolean value for a digital channel or variable within Qcode??

Andy

In your Qcode expression, the assignment of the value 0 to the variable TempResult is what gives it value type Integer. 

Image 3374

The project check warns about the conversion on line two. 


This assignment is made in two places, this is how the warning would look if you changed one to False:

Image 3375


If you change then also skip the assignment of Integer value 0 to the variable, IQANdesign will determine it is a Boolean: 

Image 3376

By eliminating the step where the variable is assigned the value 0 every cycle, you also save a little processing time and memory. 

An alternative approach could be to skip the "TempResult" variable; this is slightly more efficient: 

Image 3377

Attached project file has these variants (and one optimized by using object list) 

Avoid value type conversion in qcode.idsx