How to Programmatically Access Stored Data Values

by Janet Albers | Updated: 01/13/2016 | Comments: 6



Search the Blog

Subscribe to the Blog

Get an email when a new article is posted. Choose the topics that interest you most.

Area / Application

Product Category


Corporate / News

Enter your email address:

Suggest an Article

Is there a topic you would like to learn more about? Let us know.

Leave this field empty

All Access Pass

After you store measurements and other data in your data logger’s tables, how do you access that data to perform operations in your CRBasic program? Where can you get an all-access pass to your data? This article will explain how you can use a special CRBasic syntax to simplify the coding of your program to access your data and perform various operations.

DataTable() Structure

Typically, programs written for Campbell Scientific data loggers use one or more data tables to store measurements, calculations, and variable states. The rows of a data table are called records, and the columns are called fields.

Table with field names and record

The tables in which the data records are stored are defined by DataTable()/EndTable instructions, as well as by output processing instructions. Here is an example of this type of definition:

Data Table definitions

CRBasic Syntax

After the data is stored in tables, you can access it using a special CRBasic syntax that follows this form: TableName.FieldName. This syntax accesses the value stored in a specific field of a specific table. Optionally, you can append the syntax with a field name index and records back using this format: TableName.FieldName (FieldName Index, Records Back).

Note: When Records Back = 1, you are accessing the most recent record.


This example shows how to use the CRBasic syntax to take some data (yesterday’s maximum air temperature), which is stored in a data table, and write it to a Public variable named YesterdayMaxAirTemp. To do this, use the syntax YesterdayMaxAirTemp = Daily.AirTemp_Max,where Daily is the TableName, and AirTemp_Max is the FieldName.

Your DataTable() might look like this:

DataTable() program code

Additionally, to calculate the change in average air temperature over the previous seven days, your expression would look like this:

                AirTempDiff = Daily.AirTemp_Avg(1,1) – Daily.AirTemp_Avg(1,7)

More Information

You can find more information about additional data table syntaxes, as well as programming examples, in the CRBasic Editor. Follow these steps to access this resource:

  1. In the CRBasic Editor, click the Help option in the menu bar across the top.
  2. In the drop-down menu, select CRBasic Editor Help.

    CRBasic Editor Help

  3. In the left-hand pane, click the Index tab, and type DataTable access in the keyword box.
  4. Click overview to access the full list of syntaxes.

    Data Table Access syntax options

  5. You can click each syntax option to learn more.
    1. After you click an option, a window opens.
    2. In the window, click the Example link.
    3. A smaller window opens with an example program that uses the syntax.

I hope this article has helped you discover an all-access pass to your data. By using the CRBasic syntax to simplify your coding, you should be able to easily access and use your stored data. If you have any questions or comments, feel free to post them below.

Share This Article

About the Author

janet albers Janet Albers holds the title of Technical Communications Manager; the sign above her office door says, "Coach." 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.

View all articles by this author.


Ira | 01/13/2016 at 10:43 AM

A subtle, but important distinction to note is that FieldName doesn't necessarily equate to the variable name, which is illustrated in the examples above. The programmer should be cognizant of whether "_Max", "_Min", "_Avg" or another appendage is necessary to completely describe the FieldName.

Curt_Ingram | 01/15/2016 at 10:03 PM

I absolutely love the blogs that you post Janet!  Keep it up :)  

jra | 01/18/2016 at 08:17 AM

Right Ira. A variable name often is part of the FieldName but they are not (usually) the same. 

Thanks Curt! Let me know if you have suggestions for other topics. 

Curt_Ingram | 02/22/2016 at 08:30 PM

Janet, I would love a writeup on how to "properly" program events based on monthy or yearly change.  For example, I would like my datalogger to keep up with monthly kWhr usage.  For this to work for me now, I have to remember to reset to 0 each month (which I never do) :) 

jra | 02/23/2016 at 08:53 AM

Hi Curt! Starting with OS 28 the TimeIntoInterval() and DataInterval() instructions have a MONTH option. A line in your program, after your CallTable(), like this:

If TimeIntoInterval (0,1,Mon) Then Total_kWhr = 0

should do the trick.


The MONTH option is a little different than our other intervals. When using MONTH as the interval, the TIME INTO parameter is in seconds. Here’s a link to the change log description


If you are using an older operating system the technique in this forum post: uses RealTime() to accomplish the same thing.


I hope that helps.

Let me know what other questions you have.

Curt_Ingram | 02/29/2016 at 09:01 AM

Yay!  Thanks Janet! 

Please log in or register to comment.