Qbasic Arrays with examples

3 Min Read

QBasic is a programming language and integrated development environment (IDE) that was included with the Microsoft MS-DOS operating system. It was designed to be easy to learn and use for beginners, and it supported a variety of programming concepts, including arrays.

An array in QBasic is a collection of variables that are stored together under a single name. Arrays are useful for organizing and manipulating large amounts of data, and they can be accessed and modified using a simple syntax.These values can be accessed and manipulated through their indices, which are integer numbers that represent the position of each value in the array. Arrays are often used in QBasic to organize and manage data in a more efficient and convenient way.

To create an array in QBasic, you first need to declare the array and specify its size, which is the number of elements it will hold. For example, the following code creates an array named “myArray” that can hold 10 elements:

DIM myArray(10)

Once the array is declared, you can access and modify its elements using an index, which is a number that represents the position of each element in the array. The first element in the array has an index of 0, the second element has an index of 1, and so on.

To access an element in the array, you can use the following syntax:


For example, the following code accesses the fifth element in the array and prints its value:

PRINT myArray(4)

To modify an element in the array, you can use the same syntax and simply assign a new value to it. For example, the following code sets the sixth element in the array to the value 100:

myArray(5) = 100

You can also loop through the elements of an array and perform operations on each of them. For example, the following code uses a FOR loop to print all the values in the “myArray” array:

FOR i = 0 TO 9 
PRINT myArray(i) 

There are many other ways to use arrays in QBasic, such as declaring multidimensional arrays, sorting and searching arrays, and using array functions. For more information, you can refer to the QBasic documentation or online tutorials.

QBasic also provides several built-in functions for working with arrays, such as the LBound and UBound functions, which return the lower and upper bounds of an array, respectively. There are also functions for sorting and searching arrays, as well as for performing mathematical operations on the elements of an array.

Overall, arrays are an important concept in programming, and they are a useful tool for organizing and manipulating data in QBasic and other programming languages.

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *