Going Public with Your Variables in CRBasic

When programming your Campbell Scientific datalogger, have you ever wondered whether you should be using a Dim variable declaration or a Public one?
Janet Albers

When programming your Campbell Scientific datalogger, have you ever wondered whether you should be using a Dim variable declaration or a Public one? What is the difference between them, and when is it best to use each one?

Dim and Public variables are temporary holding locations for values that normally vary during program execution. These values are typically the result of measurements and processing or calculations.

The main difference between a Dim and a Public variable is that Dim variables do not show up in the Public table. Your program can still write to, read from, and store data from Dim variables.

Dim variables do not show up in the Public table

Tip:  Variable names, both Dim and Public, are not case sensitive.

In general, during program development you can’t go wrong declaring all variables as Public. That way, you can monitor the Public table while testing and see exactly what’s going on. After your program is running as designed, you can clean up the Public table by using the Dim declaration for variables that you don’t need to monitor as closely. Oftentimes I’ll use Dim variables for scratch calculations, loop counters, and when the Public table gets very large.

Connect With Us

envelope icon
Phone Numbers
General: (435) 227-9000
location icon
Corporate Address
815 W 1800 N
Logan, UT 84321
send icon
Email Address
sales@campbellsci.com

As a trusted leader in measurement systems for more than 50 years, our top priority at Campbell Scientific has always been to provide the most accurate, reliable data for research and industry.