0 index
1 Variable Arrays
2 Syntax
3 Initialization
4 Bounds versus Index
5 Uses
6 Control Arrays
7 Using a Control Array
8 Creating a Control Array
9 Constants
10 Uses of a constant
11 Additional uses
12 Syntax
13 Image boxes
14 Special property
15 Multitasking as a programming tool

outline
created using slideshow.cgi by Andy Harris















CSCI N331 Visual Basic: n331/vb11arrays
1. Variable Arrays
  • A list of variables, all of the same type, with similar meaning but different values each one having an index number
  • Can be any valid variable
  • Example: Putt-Putt scores



































CSCI N331 Visual Basic: n331/vb11arrays
2. Syntax
  • Dim hole(18) As Integer
        hole (0) = 1
        hole (1) = 2
        hole (2) = 3



































CSCI N331 Visual Basic: n331/vb11arrays
3. Initialization
  • Individual numeric array elements are initialized to zero by default
  • You, the programmer can explicitly initialize the array with assignment statements as in the previous slide



































CSCI N331 Visual Basic: n331/vb11arrays
4. Bounds versus Index
  • The position number contained within parentheses is called an index
  • Declaring the variable - Dim numbers (5) As Integer - would tell the computer to reserve 6 elements for an Integer array of numbers
       - the value 5 defines the upper bound (highest value) of numbers
       - the lower bound of numbers defaults to 0
  • When an upper bound is specified in the declaration, a fixed-size array is created



































CSCI N331 Visual Basic: n331/vb11arrays
5. Uses
  • A variable array frequently used in a for-next loop
  • The upper bound is frequently a constant
  • Used when you want to be able to have multiple values for properties (e.g., the same label used to display three different captions at different times)
  • Used when you are keeping track of a list or table of data (e.g., your grades)



































CSCI N331 Visual Basic: n331/vb11arrays
6. Control Arrays
  • Conceptually similar to variable arrays
  • Are an array of controls of the same type and all controls in an array share the same properties as a default (properties can be changed through code individually)
  • All controls in an array share the same code box
  • All events related to a code array automatically pass an Index parameter



































CSCI N331 Visual Basic: n331/vb11arrays
7. Using a Control Array
  • Used when several controls need to do the same thing (e.g., color box)
  • Example: you want to store images off-screen for quick access



































CSCI N331 Visual Basic: n331/vb11arrays
8. Creating a Control Array
  • Create the first object in the regular way
  • Set the properties of this object ESPECIALLY the name
  • Copy the object, paste it - a dialog box will ask you if you want to create an array
  • Click "YES" and move the new object wherever you want it. Continue this process until you have all you need.



































CSCI N331 Visual Basic: n331/vb11arrays
9. Constants
  • Treated much like variables in code except:
    - the value of a constant cannot change during the execution of the program
    - a constant cannot be given a new value during the run of the program



































CSCI N331 Visual Basic: n331/vb11arrays
10. Uses of a constant
  • A constant would be used to name a number so it is easier to use in code
  • Example: PI = 3.1415927
  • A constant would be used to refer to a commonly occurring value in a program
  • Example: NumPics = 3



































CSCI N331 Visual Basic: n331/vb11arrays
11. Additional uses
  • If the programmer updates the program to handle more frames, he only has to change the constant definition - this saves time and makes the program easier to read



































CSCI N331 Visual Basic: n331/vb11arrays
12. Syntax
  • CONST Identifier = Value



































CSCI N331 Visual Basic: n331/vb11arrays
13. Image boxes
  • Are a control to handle pictures and the property of the picture determines what image is shown
  • The picture can be copied to the clipboard, loaded from a disk file or copied from another object
  • The image box automatically resizes itself to the picture size and can be used to scale pictures



































CSCI N331 Visual Basic: n331/vb11arrays
14. Special property
  • The image box has a special property - visible that is used to hide pictures "off stage"
  • Syntax: ControlName.visible = True or False
  • True means the control is visible and is the default
  • False means the control is invisible



































CSCI N331 Visual Basic: n331/vb11arrays
15. Multitasking as a programming tool
  • Multitasking is the ability to run multiple program simultaneously on the same processor
  • Multitasking is commonly used when defining graphic elements of a visual basic program
  • Visual Basic has limited drawing features of its own but allows use of Windows Opaint or other specialized drawing programs
  • It also allows the programmer to define icons, sound effects, and other elements using specialized tools



































outline

Variable Arrays

Syntax

Initialization

Bounds versus Index

Uses

Control Arrays

Using a Control Array

Creating a Control Array

Constants

Uses of a constant

Additional uses

Syntax

Image boxes

Special property

Multitasking as a programming tool