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.

Measurement Matters - Constant Declaration


jra Jul 15, 2014 04:51 PM

Q: When should I use a Constant declaration?

A: Last week we talked about the Public and Dim variable declarations. https://www.campbellsci.com/forum/messages.cfm?threadid=7DB7BF81-14EF-451F-B23C38C77A96E962 Variables are just that, variable, they can change. Constants, on the other hand don’t change, they’re constant.

Constants can make your program more readable. I can declare:
Const PI = 3.141592654
Then, within the body of my program I can make calculations that have something to do with a circle. For example, to calculate the circumference of a circle I could use the expression: C = 2 * PI * r, where C has been declared as a variable, probably Public and r is another Constant.

Constants can also make your program versatile. Say that I have installations where the sensors are the same but the number of sensors changes from site to site. I can use a Constant for the number of sensors then use that constant elsewhere in the program for repetitions. For example:
Const NumSensors = 2
Minimum (NumSensors,MyMeasurements,FP2,0,False)
VoltSe (MyMeasurements, NumSensors,mV5000,1,1,0,250,1.0,0)

Tip: Use F9 to bring up a pick-list of declared Constants and variables when writing expressions in the CRBasic editor.

Learn more:
Using F9 and F10: https://www.youtube.com/watch?v=LndU6Z5nhv8&list=PLR_Ted9kITyIPGJ0VQiUM9OqIRTt2B_wR&index=2
Watch for a video on array notation and repetitions. Coming soon to our YouTube channel: https://www.youtube.com/user/CampbellScientific


Next week: Help Us Help You. Part 1 - Programming

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