Section 7. Installation
7.9.19.8 Formatting String Hexadecimal Variables
Table 52.
Formatting Hexadecimal Variables — Examples
Expression
Comment
Result
CRLFNumeric(1) = &H0d0a
Add leading zero to hex step 1
3338
StringVar(20) = "0" & Hex(CRLFNumeric)
Add leading zero to hex step 2
0D0A
CRLFNumeric(2) = HexToDec(Strings(20))
Convert Hex string to Float
3338.00
7.9.20 Subroutines
A subroutine is a group of programming instructions that is called by, but runs
outside of, the main program. Subroutines are used for the following reasons:
•
To reduce program length. Subroutine code can be executed multiple times
in a program scan.
•
To ease integration of proven code segments into new programs.
•
To compartmentalize programs to improve organization.
By executing the
Call()
instruction, the main program can call a subroutine from
anywhere in the program.
A subroutine has access to all
global variables
(p. 517).
Variables
local
(p. 519)
to a
subroutine are declared within the subroutine instruction. Local variables can be
aliased (as of 4/2013; OS 26) but are not displayed in the
Public
table. Global
and local variables can share the same name and not conflict. If global variables
are passed to local variables of different type, the same type conversion rules
apply as apply to conversions among variables declared as
Public
or
Dim
. See
Expressions with Numeric Data Types
(p. 162)
for conversion types.
Note
To avoid programming conflicts, pass information into local variables and /
or define some global variables and use them exclusively by a subroutine.
CRBasic example
Subroutine with Global and Local Variables
(p. 288)
shows the
use of global and local variables. Variables
counter()
and
pi_product
are global.
Variable
i_sub
is global but used exclusively by subroutine
process
. Variables
j()
and
OutVar
are local since they are declared as parameters in the
Sub()
instruction,
Sub process(j(4) AS Long,OutVar).
Variable
j()
is a four-element array and variable
OutVar
is a single-element
array. The call statement,
Call ProcessSub (counter(1),pi_product)
passes five values into the subroutine:
pi_product
and four elements of array
counter()
. Array
counter()
is used to pass values into, and extract values from,
the subroutine. The variable
pi_product
is used to extract a value from the
subroutine.
Call()
passes the values of all listed variables into the subroutine. Values are
passed back to the main scan at the end of the subroutine.
288
Содержание CR1000
Страница 2: ......
Страница 4: ......
Страница 6: ......
Страница 32: ......
Страница 36: ......
Страница 38: ......
Страница 40: ......
Страница 60: ...Section 4 System Quickstart Figure 16 PC200W View Line Graph 60 ...
Страница 96: ......
Страница 98: ...98 ...
Страница 302: ......
Страница 350: ...Section 8 Operation Figure 91 Pulse Sensor Output Signal Types Figure 92 Switch Closure Pulse Sensor 350 ...
Страница 453: ...Section 8 Operation Figure 115 Using the Keyboard Display 453 ...
Страница 454: ...Section 8 Operation 8 8 1 Data Display Figure 116 Displaying Data with the Keyboard Display 454 ...
Страница 456: ...Section 8 Operation Figure 118 Real Time Custom 456 ...
Страница 457: ...Section 8 Operation 8 8 1 3 Final Memory Tables Figure 119 Final Memory Tables 457 ...
Страница 458: ...Section 8 Operation 8 8 2 Run Stop Program Figure 120 Run Stop Program 458 ...
Страница 460: ...Section 8 Operation Figure 122 File Edit 460 ...
Страница 461: ...Section 8 Operation 8 8 4 PCCard Memory Card Display Figure 123 PCCard CF Card Display 461 ...
Страница 478: ......
Страница 506: ......
Страница 536: ......
Страница 636: ......
Страница 642: ......
Страница 644: ......
Страница 676: ......
Страница 677: ......