reference:variables_and_arrays_definitions_operation_related_commands

Variables and Arrays Definitions, Operation Related Commands

VAR Variable[=Expression][,Variable[=Expression]...]
DIM Variable[=Expression][,Variable[=Expression]...]

Define variables explicitly

・Either VAR or DIM can be used.
・Multiple variables can be defined simultaneously by separating them with commas.

Arguments

VariableNames

・Alphanumeric characters and underscores (_) can be used for variable names.
・You cannot use numbers at the beginning.

Expression

・The result of the expression becomes the initial value of the variable.
・If the expression is not specified, :Int type zero, #:Real type zero, $:empty string is set as the initial value by the type symbol (/#/$) at the end of the variable name.
・If the expression is not specified and the variable name has no type symbol, the default numeric type zero is set as the initial value.

Example

VAR A=0,B,C
DIM B$

VAR ArrayVariableName[[NumberOfElements[,NumberOfElements...]]]
DIM ArrayVariableName[[NumberOfElements[,NumberOfElements...]]]

Create an array and set it to a variable

・Either VAR or DIM can be used.

Arguments

ArrayVariableName

・If a type symbol (%/#/$) is added at the end of a variable name, an Int array, Real array, and string array are created respectively.
・If the type symbol is not specified, a default numeric type array is created.

NumberOfElements

・Specify the number of array elements to be secured with [].
・The number of elements can be created up to a 4D array by separating them with commas.
・If the number of elements is not specified, a 1D array with zero elements is created.

Example

VAR ATR[4]
VAR DX[5],DY[5],DZ[5]
DIM POS$[10,5]
DIM IMAGE[]

VAR ArrayVariableName[[NumberOfElements[,NumberOfElements...]]]=[Value1,Value2,...]
DIM ArrayVariableName[[NumberOfElements[,NumberOfElements...]]]=[Value1,Value2,...]

Create an array, set the value of the element in advance and set it to the variable

・Either VAR or DIM can be used.

Arguments

ArrayVariableName

・If a type symbol (%/#/$) is added at the end of a variable name, an Int array, Real array, and string array are created respectively.
・If the type symbol is not specified, a default numeric type array is created.

NumberOfElements

Specify the number of array elements to be secured with []

・The number of elements can be created up to a 4D array by separating them with commas.
・If the number of elements is not specified, a 1D array with zero elements is created.

Value

List of values to set as initial values for array elements

・If the number of elements is not specified, the number of values is a 1D array of the number of elements.

Example

VAR ATR[4]=[1,2,3,4]
DIM POS$[10,5]=["X","Y","Z","W"]
DIM IMAGE[]=[0,1,2,3,4]

Variable = Expression

Substitute the result of an expression into a variable

・If OPTION STRICT is not defined, the variable is automatically defined when trying to assign to an undefined variable.
・If OPTION STRICT is defined, an Undefined Variable error will occur when trying to assign to an undefined variable.

Example

A=10
B=A*6
C[4]=A+B

SWAP Variable1,Variable2

Exchange values in two variables

Argument

Variable1,Variable2

Two variables whose values are to be exchanged

Example

SWAP A,B
SWAP A[5],B[2]

INC Variable[,Expression]

Add the result of the expression to the value in the variable

Arguments

Variable

Variable to manipulate

Expression

The value to add

・If not specified, it's 1.

Example

INC X
INC X,3

DEC Variable[,Expression]

Subtract the result of the expression from the value in the variable

Arguments

Variable

Variable to subtract

Expression

The value to subtract

・If not specified, it's 1.

Example

DEC X
DEC X,3

COPY(CopySourceArray[,CopySourceOffset[,NumberOfCopyElements]])

Copy an array

Arguments

CopySourceArray

Copy source array

・Only 1D arrays can be specified.

CopySourceOffset

First element number of copy source

・If not specified, it's 0.

NumberOfCopyElements

Number of elements to copy

・If not specified, the number of elements in the copy source array minus the copy source offset is specified.

Return Value

Copy result array

・In the case of string array, the string of each element is also copied.

COPY(CopySourceString[,CopySourceOffset[,NumberOfCopyCharacters]])

Copy the string

Arguments

CopySourceString

Copy source string

CopySourceOffset

Copy source start position

・If not specified, it's 0.

NumberOfCopyCharacters

Number of characters to copy

・If not specified, the number of characters in the copy source string minus the copy source offset is specified.

Return Value

Copy result string

COPY CopyDestinationArray[,CopyDestinationOffset],CopySourceArray[[,CopySourceOffset],NumberOfCopyElements]

Copy the contents of an array to another array

・For 1D arrays only, if the copy destination array has fewer elements than the copy source array, it is automatically expanded.
・The dimensions of the array are ignored for both the copy source and the copy destination.

Arguments

CopyDestinationArray

Copy destination array

CopyDestinationOffset

First element number of the copy destination

・If not specified, it's 0.

CopySourceArray

Copy source array

CopySourceOffset

First element number of copy source

・If not specified, it's 0.

NumberOfCopyElements

Number of elements to copy

・If not specified, the number of elements in the copy source array minus the copy source offset is specified.

Example

DIM SRC[10],DST[10]
COPY DST,SRC

COPY CopyDestinationArray[,CopyDestinationOffset],LabelString[,NumberOfCopyData]

Read DATA column into array

・Read the data defined by the DATA statement into the array.
・If the number of array elements is less than the number of copy data, only 1D arrays are automatically expanded if the number of elements in the copy destination array is insufficient.

Arguments

CopyDestinationArray

Copy destination array

CopyDestinationOffset

First element number of the copy destination

・If not specified, it's 0.

LabelString

Label name string indicating the DATA statement you want to read

・Reading starts from the DATA statement that appears first after the label name.

NumberOfCopyData

Number of data to be read

・An error occurs if the number of data that can be read is less than the value specified here.
・If not specified, the number of elements in the copy destination array is specified.

Example

DIM DST[5]
COPY DST,"@SRC" 
@SRC
DATA 5,1,1,2,4

COPY CopyDestinationStringVariable[,CopyDestinationOffset],CopySourceString[[,CopySourceOffset],NumberOfCopyCharacters]

Copy part or all of a string to another string variable

Arguments

CopyDestinationStringVariable

Copy destination string variable

CopyDestinationOffset

Copy start position

・If not specified, it's 0.

CopySourceString

Copy source string

CopySourceOffset

Copy source start position

・If not specified, it's 0.

NumberOfCopyCharacters

Number of characters to copy

・If not specified, the number of characters in the copy source string minus the copy source offset is specified.

Example

COPY A$,"12345" 

RINGCOPY CopyDestinationArray,CopyDestinationOffset,CopySourceArray[[,CopySourceOffset],NumberOfCopyElements]
RINGCOPY CopyDestinationArray,CopyDestinationOffset,CopySourceArray[[,CopySourceOffset],NumberOfCopyElements] OUT Variable

Recognize array as ring buffer and copy data to it

・Similar to the COPY command, the value between arrays is copied, but even if the number of copy elements at the copy source is larger than the copy destination, the number of elements is not expanded and the data is copied by folding back to the beginning of the array.
・You can specify up to a 2D array for both the copy destination and copy source. When a 2D array is specified, it is handled as a multi-channel ring buffer (or data).
・If a 2D array is specified for both the copy destination and the copy source, the number of channels (number of elements in the first dimension) must be the same.
・When the copy destination is 2D and the copy source is a 1D array, the copy source data is copied to all channels of the copy destination in the same way.
・Operation is not guaranteed if the copy destination and copy source are the same array.

Arguments

CopyDestinationArray

Array treated as a copy destination ring buffer

CopyDestinationOffset

Copy start position at the copy destination

CopySourceArray

Copy source array

CopySourceOffset

Copy start position at the copy source

・0, if not specified.

NumberOfCopyElements

Number of elements to copy

・If not specified, it's the number of elements in the copy source array.

Return Value

End position of copied data

・When handled as a ring buffer, the returned value is the next copy destination offset.

SORT [StartPosition,NumberOfElements,]Array1[,Array2,...]

Sort the array in ascending order

Arguments

StartPosition

Position to start sorting in Array1

・0, if not specified.

NumberOfElements

Number of elements to sort

・If not specified, it's the number of elements in Array1.

Array1

An array containing the numbers to sort

Array2

Array to be sorted in conjunction with the sorting result of Array1.

・Array 2 to 8 can be omitted.
・Array 2 to 8 can be string arrays.

Example

DIM WORK[10]
SORT 0,10,WORK

RSORT [StartPosition,NumberOfElements,]Array1[,Array2,...]

Sort the array in descending order

Arguments

StartPosition

Sort start position in Array1

・0, if not specified.

NumberOfElements

Number of elements to sort

・If not specified, it's the number of elements in Array1.

Array1

An array containing the numbers to sort

Array2

Array to be sorted in conjunction with the sorting result of Array1.

・Array 2 to 8 can be omitted.
・Array 2 to 8 can be string arrays.

Example

DIM WORK[10]
RSORT 0,10,WORK

PUSH Array,Expression

Add elements to the end of an array

・The number of elements increases by one.

Arguments

Array

The array to add the element to

Expression

The value of the element to add

Example

DIM WORK[10]
PUSH WORK,123

POP(Array)

Extract elements from the end of an array

・The number of elements reduces by one.

Argument

Array

The array whose elements are to be retrieved

Return Value

The value of the extracted element

Example

DIM WORK[10]
PUSH WORK,123
A=POP(WORK)

UNSHIFT Array,Expression

Add elements to the beginning of an array

・The number of elements increases by one.

Arguments

Array

The array to add the element to

Expression

The value of the element to add

Example

DIM WORK[10]
UNSHIFT WORK,123

SHIFT(Array)

Extract elements from the beginning of an array

・The number of elements reduces by one.

Argument

Array

The array whose elements are to be retrieved

Example

DIM WORK[10]
UNSHIFT WORK,123
A=SHIFT(WORK)

FILL Array,Value[,Offset[,NumberOfElements]]

Set all array contents to the specified value

・The array type may be an Int, Real or string.
・Partial change is possible by specifying offset and number of elements.

Arguments

Array

Array to overwrite values

Value

Number or string

Offset

The position at which to start writing the value

NumberOfElements

Number to write

Example

DIM WORK[10]
FILL WORK,0

TYPEOF(Value)

Find the value type

Argument

Value

The value whose type is to be examined

Return Value

Depending on the value type, one of the following numbers is returned:

0 Default Type #T_DEFAULT
1 Int type #T_INT
2 Real Type #T_REAL
3 String Type #T_STR
5 Int Array #T_INTARRAY
6 Real Array #T_REALARRAY
7 String Array #T_STRARRAY

・The default type is a special type that is set when an argument is not specified in a function/command call.

ARRAY%(NumberOfElements[,NumberOfElements...])
ARRAY#(NumberOfElements[,NumberOfElements...])
ARRAY$(NumberOfElements[,NumberOfElements...])

Create an array

・Use this when you want to create an array other than when defining a variable with VAR.
・ARRAY% creates an Int array, ARRAY# creates a Real array, and ARRAY$ creates a string array.

Argument

NumberOfElements[,NumberOfElements...]

Array dimensions and number of elements to create

Return Value

Created array

DIM(Array)
DIM(Array,Dimension)

Check the number of array dimensions and the number of elements in each dimension

Arguments

Array

The array to check

Dimension

Dimension to check the number of elements: 0 to 3

・If not specified, the number of array dimensions is returned.

Return Value

・If a dimension is specified, the number of elements in the specified dimension is returned.
・If the dimension is not specified, the number of array dimensions is returned.

Example

DIM WORK[10,20]
? DIM(WORK)
? DIM(WORK,0)
? DIM(WORK,1)

RESIZE Array,NumberOfElements[,NumberOfElements...]

Change the size of an array

・The numeric value 0 or an empty string is entered in the element of the extended part.

Arguments

Array

The array to resize

NumberOfElements

Number of elements after resizing

・You can change only the number of elements written first when defining an array.
・Dimensions cannot be changed.

INSERT Array,InsertionPosition[,NumberOfElements[,InitialValue]]

Insert elements into a 1D array

Arguments

Array

Array to increase elements

InsertionPosition

Element insertion position: 0 to the number of array elements

NumberOfElements

Number of elements to insert: positive number

・1, if not specified.

InitialValue

Insert element value

・If not specified, 0 for numeric arrays and empty string for character arrays.

REMOVE Array,DeletionPosition [,NumberOfElements]

Delete 1D array elements

Arguments

Array

The array to remove elements from

DeletionPosition

Element deletion position: 0 to number of array elements -1

NumberOfElements

Number of elements to delete: positive number

・1, if not specified.

FIND(Array,Value)

Search an array for a specified value and return the found position

Arguments

Array

Target array to search

・Multi-dimensional arrays can also be specified.

Value

The value to search for

Return Value

Found position

・If the value is not found, -1 is returned.

Example

DIM A[]=[1,2,3,4,5]
?FIND(A,3)

FIND Array,Value OUT Index1[,Index2...]

Search an array for a specified value and return the found position

Arguments

Array

Target array to search

・Multi-dimensional arrays can also be specified.

Value

The value to search for

Return Value

The index of the found position

・The number of returned values must be the same as the number of dimensions of the searched target array.
・If no value is found, -1 is returned for all return values.

Example

DIM A$[3,3]=["1","2","3","4","5","6","7","8","9"]
FIND A$, "4" OUT Y,X
?A$[Y,X]

INSPECT Value

Display detailed value information

・For type, value, and array, the number of elements and the values of all elements are displayed.
・For strings and string variables, the length of the string is also displayed.
・If the content of the string is too long, the rest is omitted.
・It can be abbreviated as ?? instead of using INSPECT.

Example

INSPECT A
?? "12345"*10

reference/variables_and_arrays_definitions_operation_related_commands.txt · Last modified: 2023/12/07 15:55 (external edit)

Page Tools