Getting Started
Introduction
Sample Programs
QBasic IDEs
History
Advice
Tools
Mini-Tutorial
Tutorial
Code Snippets

Resources
Web Sites
More Tutorials
Vendors
Books
Magazines
NewsLetters
NewsGroups
Forums
User Groups
Talk Shows
Blogs

GBIC >> QBasic >> Tutorial >> Arrays

QBasic Information Center Tutorials - Arrays
These tutorials were written to help you get a quick, but thorough, understanding of QBasic - the scope of the language as well as it's specific capabilities.

Array Functions Summary
The good news is that QBasic support arrays. The bad news is that the support is fairly minimal, with only a handful of functions available.

    • Properties
     ubound, lbound 
    • Assignment
     erase 
    • Declaration
     option base 

Array Code Snippets
The following code shows several methods of manipulating arrays.

     Dim x$(5)         # declare array
     Dim x$(5,1)       # declare two-dimensional array

     x$(1) = "hello"   # assigns value to array element 1
    
     erase x$          # clears an array

Array Functions Reference
Here's a quick reference of the available array functions, in alphabetical order.

  • ubound - returns upper array index
        Dim x(5), y(5,7)
        result = ubound(x)            # returns 5
        result = ubound(x,2)          # returns 7
        

  • lbound - returns lower array index
        Dim x(-7 to 5, 4 to 6)
        result = lbound(x)            # returns -7
        result = lbound(x,2)          # returns 4
        

  • erase - reset all values of the array
        Dim x(5)       # create array x
        x(1) = 2       # x(1) is set to 2
        erase x        # x(1) is now = 0
        

  • option base - set lower array index of all arrays to 0 or 1
        option base 0         # sets lower index of arrays to 0
        Dim x(5)              # lower index of x is 5
        option base 1         # sets lower index of arrays to 1
        Dim x(5)              # lower index of x is 1
        

If you have any suggestions or corrections, please let me know.