String Constants, Variables & Operators


A string is a sequence of alphanumeric characters (8-bit ASCII codes) which collectively form an entity.

1.     String Constants

A string constant may contain from 0 to 70 characters enclosed in double quotation marks. e.g.

"TBASIC made PLC numeric processing a piece of cake!"
"$102,345.00"

2.     String Variables

TBASIC supports a maximum of 26 string variables A$, B$ ... Z$. Each string variable may contain from 0 (null string) up to a maximum of 70 characters.

Note: For M-series PLC with firmware version r44 and above, you can access the 26 string variables using an index: $$[1] to $$[26]. I.e. A$ is the same as $$[1], Z$ is the same as $$[26]. Note that $$[1] to $$[26] are not additional string variables, it just give you a way to index the string variables not possible on previous firmware version. Also, only TRiLOGI version 5.2 and above properly support these variable names. Caution: Do not try to transfer a program using $$[n] variable to a PLC with firmware earlier than r45 as it can cause the PLC operating system to crash.

3.     String Operators

i) Assignment Operator: A string variable (A to Z, DM and system variables, etc) may be assigned a string expression using the assignment statement:

A$ = "Hello, Welcome To TBASIC"
Z$ = MID$(A$,3,5)

ii) Concatenation Operators: Two or more strings can be concatenated (joined together) simply by using the "+" operator. e.g.

M$ = "Hello " + A$ + ", welcome to " + B$

If A$ contains "James", and B$ contains "TBASIC", M$ will contain the string: "Hello James, welcome to TBASIC".

iii) Comparison Operators: Two strings may be compared for equality by using the function STRCMP(A$,B$). However, the integer comparator such as "=", "<>", etc cannot be used for string comparison.

iv) Functional Operators: TBASIC supports a number of statement and functions which take one or more string arguments and return either an integer or a string value. e.g.

LEN(x$), MID$(A$,x,y), PRINT #1 A$,.... SETLCD 1, x$ VAL(x$),


backbutton.gif (507 bytes)  Basic to TBASIC Reference Manual