3 how collections work, 1 visual basic view of collections, 1 accessing collections with for each – Campbell Scientific LoggerNet-SDK Software Development Kit User Manual

Page 32: 2 accessing collections with indexes and names, 2 delphi/visual c++ view of collections

Advertising
background image

Section 6. CsiBrokerMap Control

6.3 How Collections Work

The CsiBrokerMap uses the concept of collections in its implementation.
Collections provide layers of objects and a standard way to access those
objects. There are two basic ways to look at collections. The Visual Basic
(VB) view describes how a VB programmer would view a collection, which is
simpler than for Delphi or Visual C++.

6.3.1 Visual Basic View of Collections

The CsiBrokerMap collections are simply three levels of grouped items.
Brokers exist at the top-most level. Then within Brokers are Tables, and
within Tables are Columns. Each of these levels can be accessed with the dot
operator in Visual Basic. The following example illustrates how to access all
of the Brokers in the BrokerMap:

6.3.1.1 Accessing Collections with For Each

For Each b in BrokerMap.Brokers
Debug.Print b.name
Next

This simplistic code allows you to iterate through the BrokerMap simply
without having to worry about indexes and going out of bounds. In the code
above, it would be possible to access all of the tables in each broker by nesting
a similar loop inside the existing one stating

For Each t in

BrokerMap.Brokers(b).Tables.

By repeating similar code for the

columns the whole broker map could be displayed.

6.3.1.2 Accessing Collections with Indexes and Names

The brokers, tables, and columns can be accessed not only with the “

For

Each

” loop, but also by index and name. Consider the following examples:

BrokerMap.Brokers("CR9000").Tables("minute").Columns("temp").size
For i = 0 to BrokerMap.Brokers.Count – 1
Debug.Print BrokerMap.Brokers(i)
Next

The first line of code assumes that a datalogger named CR9000 with a table
named minute exists in the broker map. The code also assumes a column
named temp exists in the table named minute. These names could also be

String

variables instead of literal strings.

6.3.2 Delphi/Visual C++ View of Collections

Delphi and Visual C++ require a little more work to capture the information
provided by this control, but not much more than Visual Basic's iterative
method using indexes. Please refer to the code in the Delphi and Visual C++
examples included with the LoggerNet SDK installation.

6-2

Advertising