chapter 2: preliminaries

17
Excel Macros Level 1 Preliminaries

Upload: matthew-campbell

Post on 05-Dec-2014

364 views

Category:

Education


4 download

DESCRIPTION

Slides for Chapter 2 of Excel Macros Level 1: Preliminaries

TRANSCRIPT

Page 1: Chapter 2: Preliminaries

Excel Macros Level 1

Preliminaries

Page 2: Chapter 2: Preliminaries

M. Campbell - 2010 2

Programming Languages

Allows us to express computations that a machine can perform

Can be used to: Control behaviour of a machine Express an algorithm Communicate

4/29/2010

p. 9

Page 3: Chapter 2: Preliminaries

M. Campbell - 2010 3

High Level Languages

Low Level Languages

Application Level Languages

4/29/2010

p. 9

Page 4: Chapter 2: Preliminaries

M. Campbell - 2010 4

High Level Languages

Low Level Languages

Application Level Languages

4/29/2010

Page 5: Chapter 2: Preliminaries

M. Campbell - 2010 5

Low Level Languages

Designed to manipulate the computer via: The operating system (i.e. Windows, Linux) The hardware

Examples include: Assembly language Machine code

4/29/2010

Page 6: Chapter 2: Preliminaries

M. Campbell - 2010 6

Machine Language Sample

mem[0]=0x23;mem[1]=0x00;mem[2]=0xa8; mem[3]=0x17; mem[4]=0xa9; mem[5]=0x17; mem[6]=0xaa;

4/29/2010

Page 7: Chapter 2: Preliminaries

M. Campbell - 2010 7

High Level Languages

Low Level Languages

Application Level Languages

4/29/2010

Page 8: Chapter 2: Preliminaries

M. Campbell - 2010 8

High Level Languages

Designed to be easy to read and write inUsed to create most applications (i.e. Excel)Examples include:

BASIC C, C++, C# Pascal COBOL Python

4/29/2010

Page 9: Chapter 2: Preliminaries

M. Campbell - 2010 9

C# Sample

// Hello1.cs public class Hello1 {

public static void Main() {

System.Console.WriteLine("Hello, World!"); }

}

4/29/2010

Page 10: Chapter 2: Preliminaries

M. Campbell - 2010 10

High Level Languages

Low Level Languages

Application Level Languages

4/29/2010

Page 11: Chapter 2: Preliminaries

M. Campbell - 2010 11

Application Level Languages

Used to manipulate an application program such as Excel, Word, PowerPoint

Examples include: Excel VBA Word VBA PowerPoint VBA

4/29/2010

Page 12: Chapter 2: Preliminaries

M. Campbell - 2010 12

Excel VBA Sample

Sub SampleWalkthrough() Dim oCell As Range Dim x As Integer For Each oCell In Selection.Cells oCell.Value = x x = x + 1 NextEnd Sub4/29/2010

Page 13: Chapter 2: Preliminaries

M. Campbell - 2010 13

Programming Style

Two important conventions: Make your program readable Have lots and lots of comments

4/29/2010

p. 11

Page 14: Chapter 2: Preliminaries

M. Campbell - 2010 14

Readability

Aim for clarity of code over cleverness

4/29/2010

p. 12

Page 15: Chapter 2: Preliminaries

M. Campbell - 2010 15

Comments

Preceded by a 'Aim for comments to describe the programCan write the comments first (i.e. the logic)

and then fill in the code afterwards

4/29/2010

p. 11

Page 16: Chapter 2: Preliminaries

M. Campbell - 2010 16

Modularity

Use code modules to isolate repetitive code Helps to shorten code Improves readability of code

4/29/2010

p. 14

Page 17: Chapter 2: Preliminaries

M. Campbell - 2010 17

Modularity

Two types of code modules:

Functions: Return a value when finished

Subroutines: Do not return a value upon finishing

Collectively referred to as procedures

4/29/2010

p. 15