Arraylec_2011 - 9/26/2011 LearningObjectives Arrays...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
9/26/2011 1 Learning Objectives Arrays as subscripted variables Dim statements Dynamic dimensioning 1 Arrays Arrays are a group of numbers whose elements are arranged in a single or multi dimensional format The elements are accessed using index notation The elements are of the same data type (e.g., matrix with real numbers or integer numbers) Used to store large sets of numbers 3 Array Declaration Arrays are indicated by subscripted variables in VBA programs Must tell computer that your variable is an array and tell the maximum number of members in the array If x is an array of integers with 30 members, x 1 x 30 Use Dim x(30)as integer Dim statement must appear before any x is used 4 Array member type must be declared Can define more than one array in a line: Dim A(10) as double, B(20) as single, C(40)as integer Array Declaration 5 Array indexes go from 0 to the number specified For A(30), you can store values at A(0), A(1). . To A(30), and this (starting the index at 0) can be confusing Another approach to size the array is to use A(1 to 30), which will start from A(1). One way to default the index of the first array member to 1 is to use the statement “ Option Base 1 ” at the top of the program. This will force the array to start at 1. For example: Option Base 1 Dim AA(30) as integer In AA(30), you can store values at AA(1), AA(2). . To A(30) Array Declaration 6 Without Dim, VBA would think the array variable a function–you will see an error message It important that array members not exceed the maximum number specified in the Dim statement For example: Option Base 1 Dim grades(15) as single Sum = 0 Fori= 1 to 20 sum = sum + grades(i)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/14/2011 for the course CE 3010 taught by Professor Clement during the Fall '09 term at Auburn University.

Page1 / 4

Arraylec_2011 - 9/26/2011 LearningObjectives Arrays...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online