Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

ConstTable rounds entered values


pokeeffe Oct 30, 2019 12:31 AM

Anyone know why `ConstTable` instruction in CR1000.Std.32.02 would entered values to nearest integer? Such behavior is not described in the user manuals, editor help files, or this forum, but is reproducible:

1. Run program in CR1000.Std.32.02 that contains named constant table:

ConstTable(Constants) 'HINT named so can modify via LoggerNet
  Const UTC_OFFSET = -8  'hrs, logger offset relative to UTC time
  Const WXT_AZIMUTH = 0  'orientation w.r.t. True North, degrees
  Const PAR_MULT = 0 'unique sensor calibration, umol/(mV s m^2) - NEGATIVE for LI-190SA wiring convention
EndConstTable

2. Connect using LoggerNet 4.5 Connect application

3. View the constants table

4. Type "-197.63" into `PAR_MULT` field.

5. Observe value transform to "-198"

6. Retrieve program file from logger.

7. Confirm constant was updated to -198.


Sam Oct 30, 2019 12:12 PM

When the program compiles, he compiler determines the type of the constant (e.g. Long, Float, Boolean) from the expression. This datatype is communicted to the software. The software formats or restricts the input based on the datatype communicated to it by the logger. In the example, the datalogger is storing the constant as a Long. The software subsequently restricts input to an integer. 

You can declare a constant with or without specifying a data type. If a data type is not specified, the compiler determines the type of the constant from the type of the expression. A numeric integer literal is cast by default to the Long data type. The default data type for floating-point numbers is Float, and the keywords True and False specify a Boolean constant.

You can force a literal to be stored as a particular data type. You can use the As syntax to denote the constant should be treated As Long, As Float, etc. Alternatively, you can provide the number in a format that tips the compiler to assume a different format. For example 0.0 instead of 0.

So one (or more) of the following would result in the behavior your after.

 Const PAR_MULT As Float = 0 
 Const PAR_MULT = 0.0 


pokeeffe Oct 30, 2019 04:47 PM

Thank you Sam! 💯 This is precisely the info I was missing.


netskink Dec 11, 2021 06:56 PM

Hmm, there is a bug with this capability.  If the constant ends in 0, as in -1.0, it will be treated as an integer.

-1.0 -> -1

-1.1 -> -1.1

Log in or register to post/reply in the forum.