Campbell Scientific CR1000KD CR800 and CR850 Measurement and Control Systems - Page 117
For/Next, TempC, TempC1, VariableNamex, VariableName x,y,z
View all Campbell Scientific CR1000KD manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 117 highlights
Section 7. Installation simply declare a variable array as shown below: Public TempC(4), This creates in memory the four variables TempC(1), TempC(2), TempC(3), and TempC(4). A variable array is useful in program operations that affect many variables in the same way. CRBasic example Using a variable array in calculations (p. 117) shows program code using a variable array to reduce the amount of code required to convert four temperatures from Celsius degrees to Fahrenheit degrees. In this example, a For/Next structure with a changing variable is used to specify which elements of the array will have the logical operation applied to them. The CRBasic For/Next function will only operate on array elements that are clearly specified and ignore the rest. If an array element is not specifically referenced, e.g., TempC(), CRBasic references only the first element of the array, TempC(1). CRBasic Example 7. Public TempC(4) Public TempF(4) Dim T Using a Variable Array in Calculations BeginProg Scan(1,Sec,0,0) Therm107(TempC(),4,1,Vx1,0,250,1.0,0) For T = 1 To 4 TempF(T) = TempC(T) * 1.8 + 32 Next T NextScan EndProg Dimensions Some applications require multi-dimension arrays. Array dimensions are analogous to spatial dimensions (distance, area, and volume). A single-dimension array, declared as VariableName(x), with (x) being the index, denotes x number of variables as a series. A two-dimensional array, declared as Public (or Dim) VariableName(x,y) with (x,y) being the indices, denotes (x * y) number of variables in a square x-byy matrix. Three-dimensional arrays (VariableName (x,y,z), (x,y,z) being the indices) have (x * y * z) number of variables in a cubic x-by-y-by-z matrix. Dimensions greater than three are not permitted by CRBasic. When using variables in place of integers as the dimension indices, e.g., CRBasic example Using variable array dimension indices (p. 117), declaring the indices As Long variables is recommended as doing so allows for more efficient use of CR800 resources. 117