Sorting of an array

Sorting of an array is arranging of its members in a ascending or descending order. This can be achieved in many ways, and in the text that follows you will see one of the variants of the algorithm called Bubble Sort. It works by running two loops and then, depending on their index values, corresponding members of the array are compared. If the condition is met they change places. The procedure is repeated until the comparison is completed, and array sorted.

Calling a subroutine

During program development it’s important to notice which of its parts can be reused and, based on that fact, should create subroutines that will be called within the main program. Subroutines can be functions and procedures. We use the functions by specifying the variable name, followed by equality sign, and then the name of the function with the arguments. We invoke the procedures using the Call command, after which we specify the procedure name with the arguments.

Error handling

Errors happen! If there is a critical place in the program where we think that an error may occur it is necessary to mark it and further redirect the program flow to the message that should be displayed if it occurs. For managing the program flow, with and without error, we can use the GoTo command. In combination with On Error we get a powerful tool that helps us take the necessary action immediately after the error is detected.

Variable scope and lifetime

The variable, after declaration, has its own lifespan and it lasts until the subroutine in which it was created is completed. Sometimes we want her to keep its value even after leaving the subroutine. Also, the variable is visible only within the module in which the it is located. Is there a need for it to be seen outside the module? How to define the range and extend the life span of variables will be found in the text that follows.

Dynamic arrays

Sometimes we need to make an array that we are not sure of how many members will have. In this case should create dynamic arrays that, unlike the usual ones, do not have a fixed length. These arrays are declared in such a way that the number of members is omitted, and how many of them will be, or for how long the number of members of array should be increased is subsequently defined with commands that will be discussed in the text that follows.