Infobasic Programming
Infobasic Programming
Introduction
Arrays
Dimensioned Arrays
Dynamic Arrays
* Prints
[F1V1][F1V2][F2V1][F2V2S1][F2V2S2][NEWFIELD][F10]
Note the difference here between using INS to load field 10 and using
...<10>=.... A simple assignment would have overwritten the value in field
10. INS actually inserts a new field at that position, pushing the value [F10]
out into field 11.
PRINT DYNARRAY
[F1V1][F1V2][F2V1][F2V2S1][F2V2S2][F10]
The string F10 is now back in field 10.
If you wish to find a string within your dynamic array, you can do so using the
LOCATE statement:
* Finds [F10] at field number 10 and prints '10'
Note the <1> after the DYNARRAY array name in this code. This indicates
that the search should begin with field 1, but more importantly it indicates
that the string being searched for is a complete field. Compare the following:
* Fails to find [F1V2] because it is not a complete field, and prints 'Not found'
LOCATE '[F1V2]' IN DYNARRAY<1> SETTING POSITION THEN
PRINT POSITION
ELSE
PRINT 'Not found'
END
The <1,1> not only defines the starting position for the search, it indicates
that the search must find a value within field 1. The general principle remains
that you can only search 'one level down': you can search an entire dynamic
array for a complete field, a field for a value, or a value for a subvalue. As the
result is returned as a single number and not a set of coordinates, it could not
be otherwise. How would LOCATE report finding [F1V2] in field 1, value 2, by
returning a single number?
LOCATE really comes into its own, however, when dealing with a field only list
(containing no values or subvalues): particularly if the fields are in sorted
order. Consider the following:
* Prints nothing
PRINT POSITION ;
* Prints 4
LOCATE 3 IN NEWARRAY <1> BY 'AR' SETTING POSITION ELSE PRINT '3 absent'
First, to explain the BY 'AR' clause. This optional clause informs LOCATE that it
is dealing with a sorted list: the AR denotes the sort order: ascending rightjustified. AL stands for ascending left justified, DR for descending right
justified, and DL for descending left justified.
One advantage of the BY clause is that it can speed up your search. If your
list is sorted AR, and you are looking for the value 3, jBase knows that it can
give up the search as soon as it reaches the first string higher than 3: which it
does when it gets to 4. It therefore doesn't have to search the entire dynamic
array for a value that is not there unless the value it is looking for happens to
be bigger than all the fields already in the array.
More importantly, though, it adds an interesting twist to the action of
the SETTING clause in the case where the string searched for cannot
be found: as the variable following SETTING is set to the position the
string would have been in if it had been found. By using INS to insert
the string in this position, the dynamic array can be maintained in a sorted
order without the need for a sorting algorithm.
This is a very neat and widely used trick. The code runs as follows:
LOCATE STRING IN SORTEDARRAY<1> BY SORTORDER SETTING POSITION ELSE
INS STRING BEFORE SORTEDARRAY<POSITION>
END
SUBROUTINE SubroutineName
Statement 1
Statement 2
Statement 3
RETURN
END
** Never store user written programs/subroutines in GLOBUS.BP directory
Compiling and Cataloging Routines
Once cataloged, the program can be run like any other commands. The RUN
command can be used to run a program without cataloging, but you should
catalog your program whenever possible.
Executables and shared library objects can be removed from the bin and lib
directories by using the DECATALOG command.
For Program, go to the database prompt, write the program name and press Enter
For Subroutine, login to T24, make an entry in PGM.FILE, write the subroutine name
in the command line and press Enter
Control Structure
IF THEN ELSE
It may take two different forms being single and multiple line statements.
In most cases, either THEN or ELSE must be specified.
Example:
IF AGE GT 18 THEN PRINT ADULT ELSE PRINT MINOR
IF AGE GT 18 ELSE PRINT MINOR
IF AGE GT 18 THEN PRINT ADULT
IF AGE GT 18 THEN
PRINT ADULT
END
ELSE
PRINT MINOR
END
FOR LOOP
FOR COUNTER=1 TO 10
CRT COUNTER - : COUNTER
NEXT COUNTER
LOOP
LOOP
REPEAT
** The condition is held in the WHILE or UNTIL clause. In case of WHILE, NUMBER
FOUND will be displayed if VAR contains a value. But in case of UNTIL, NUMBER
FOUND will be displayed if VAR contains no value.
LEN
o
VAR = LEN(PRIME)
COUNT
o
DCOUNT
o
Return the number of records
VAR = ABC@VMDEF@VMGHI
I = DCOUNT(VAR,@VM)
UPCASE
o
DOWNCASE
o
VAR = CHANGE(PRIIME,II,I)
OCONV
o
Output conversion
o
VAR = DOWNCASE(PRIME)
CHANGE
o
VAR = UPCASE(prime)
DATE = OCONV(TIME(),MTS)
ICONV
o
o
Input conversion
TIME = ICONV(Y.TIME,MTS)
Insert Files
I_COMMON
o
Defines all the common global variables that can be used across
subroutines.
I_EQUATE
o
Initializes all the common variables
Some common variables get loaded when a user signs on while some
variables get loaded while opening specific applications or performing specific
actions.
Ctrl + C