I’ll find out tomorrow when the sun comes out. I had tried to declare DuskSensor As Double but that wasn’t the answer.
Var DuskSensor As Integer = Dictionary_Temperature.Value(“Dusk Sensor”)*100
to
Var DuskSensor As Double = Dictionary_Temperature.Value(“Dusk Sensor”)*100
I will change it to:
Var DuskSensor As Integer = Dictionary_Temperature.Value(“Dusk Sensor”)*100.0
I think Xojo changes the Variant according to the operation and not to the defined var, in other words, even if you change it to As Double the operation will still be Integer.
As mentioned above here’s the documentation about it: Variant - Xojo Documentation under Automatic conversion of values
Variants used in an expression convert themselves to the type of the other operand, no matter what kind of data they contain, instead of deferring the type-conversion until runtime.
So in:
Var DuskSensor As Integer = Dictionary_Temperature.Value("Dusk Sensor")*100
the value from Dictionary_Temperature.Value("Dusk Sensor") will be an Integer as you’re using 100 (integer) instead of 100.0 (double). 0.25 as an integer will be 0 so you’ve got 0*100 = 0
The correct way would be:
Var DuskSensor As Integer = Dictionary_Temperature.Value("Dusk Sensor").DoubleValue * 100
as double * integer will be worked out as a double then the answer of that converted to an integer to store in the DuskSensor variable.
or
Var DuskSensor As Integer = Dictionary_Temperature.Value("Dusk Sensor") * 100.0
so you have double * double with the answer being converted to an Integer
Great exclamation of the problem guys. It’s nice to have a breakdown as a teacher might so us less knowledgeable might better understand a concept. I also had no idea about ctype which is interesting for converting integers to boolean. Useful stuff.
// Convert Integer to Boolean
// 0 converts to False
// non-zero converts to True Var i AsInteger = 42
P.S. When the sun came out this morning all was well!
I was actually able to fined 10 places in my home automation software that I was unknowingly converting temperatures stored in a dictionary to integers. CType fixed that issue.