The Benefits of Using Constants in CRBasic

por Janet Albers | Actualizado: 08/05/2015 | Comentarios: 0

Mensajes del blog relacionados


Etiquetas

CRBasic

Temas Blog


Buscar en el Blog


Suscribirse al Blog

Configure sus preferencias para la recepción de notificaciones por email cuando se publiquen nuevos artículos en el blog que coincidan con sus áreas de interés.


Entre su dirección email:



Sugerir un Artículo

¿Hay algún tema sobre el cual desea saber más? Háganoslo saber. Por favor sea lo más específico que pueda.

Leave this field empty

F9 and F10 keys

Why should you use a Constant declaration in your CRBasic program? What is a Constant anyway? In a previous article ("Going Public with Your Variables in CRBasic"), we talked about the Public and Dim variable declarations. Variables are just that—variable; they change. Constants, on the other hand, don’t change; they’re constant.

Constants can make your program more readable.

For example, you can declare: Const PI = 3.141592654. 

Then, within the body of your program, you can make calculations that have something to do with a circle.

Constants can make your program more readable.

For example, to calculate the circumference of a circle, you 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 you have installations where the sensors are the same, but the number of sensors changes from site to site. You can use a Constant for the number of sensors and then use that constant elsewhere in the program for repetitions.

For example:


Const NumSensors = 2
Public MyMeasurements(NumSensors)
…   Minimum (NumSensors,MyMeasurements(),FP2,0,False)
…   VoltSe (MyMeasurements(), NumSensors,mV5000,U1,1,0,250,1.0,0)

Pi as a constant

Tip: Use the F9 or F10 keys on your keyboard to bring up a pick-list of declared Constants and variables when writing expressions in the CRBasic Editor. F9 inserts the variable, whereas F10 replaces what is already there.  

Recommended for You: For more information, watch our "CRBasic | Features" video. Also watch our "CRBasic | Advanced Programming" video that further explains array notation and repetitions.


Compartir este artículo



Acerca del autor

janet albers Janet Albers is a Senior Technical Writer. She'll share tips, simplify concepts, and guide you to a successful project. She's been at Campbell Scientific, Inc. longer than the CR1000, but not quite as long as the CR10X. After work hours, Janet enjoys the outdoors with her boys and dogs.

Ver todos los artículos de este autor.


Comentarios

Please log in or register to comment.