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 and all F-Series PLCs, 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 i-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.

NEW! With i-TRiLOGI version 6.2 and above, you can now attach comments to any variable name of any length to make program easier to read. See section 4 (String Variable Comments) below for more details.

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$),

4.     String Variable Comments

With i-TRiLOGI version 6.2 and above, you can now attach comments to any variable name of any length to make program easier to read. The compiler will ignore any alphanumeric characters (A to z, 0 to 9 and ‘_’) that are attached behind the variable name following an underscore character “_”. It is important to understand that by appending these comments to variables, no new variables are being created.

For Example: "A$_Some_String" corresponds to "A$" (or $$[1]).

A string variable (such as A$) can have different comments each time it is referenced in the same program because the compiler ignores the comments anyways. Although, in most cases it may be best to limit a variable to one comment to avoid potentially overwriting data since no new variables are actually create, as mentioned above.

For Example: If a string variable, A$, was named "A$_one_string" in one part of a program and named "A$_two_string" in another part of the program, then they will still both refer to A$. If each variation has different string data, then the data that was stored in the last variation that was updated will be the data in A$. Then if the previous variation is accessed, it wont contain the data that was originally stored in it.

6.     Variable Define Table (NEW!)

This new feature allows you to define an acceptable name for any variable, constant or even an entire expression. Click here for more details.


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