Excel Macros Level 1Preliminaries
Programming LanguagesAllows us to express computations that a machine can performCan be used to:Control behaviour of a machineExpress an algorithmCommunicate4/29/2010M. Campbell - 20102p. 9
4/29/2010M. Campbell - 20103p. 9
4/29/2010M. Campbell - 20104
Low Level LanguagesDesigned to manipulate the computer via:The operating system (i.e. Windows, Linux)The hardwareExamples include:Assembly languageMachine code4/29/2010M. Campbell - 20105
Machine Language Samplemem[0]=0x23;mem[1]=0x00;mem[2]=0xa8; mem[3]=0x17; mem[4]=0xa9; mem[5]=0x17; mem[6]=0xaa; 4/29/2010M. Campbell - 20106
4/29/2010M. Campbell - 20107
High Level LanguagesDesigned to be easy to read and write inUsed to create most applications (i.e. Excel)Examples include:BASICC, C++, C#PascalCOBOLPython4/29/2010M. Campbell - 20108
C# Sample// Hello1.cs public class Hello1 { 	public static void Main() 	{ System.Console.WriteLine("Hello, World!"); } } 4/29/2010M. Campbell - 20109
4/29/2010M. Campbell - 201010
Application Level LanguagesUsed to manipulate an application program such as Excel, Word, PowerPointExamples include:Excel VBAWord VBAPowerPoint VBA4/29/2010M. Campbell - 201011
Excel VBA SampleSub SampleWalkthrough()    Dim oCell As Range    Dim x As Integer    For Each oCell In Selection.CellsoCell.Value = x       x = x + 1    NextEnd Sub4/29/2010M. Campbell - 201012
Programming StyleTwo important conventions:Make your program readableHave lots and lots of comments4/29/2010M. Campbell - 201013p. 11
ReadabilityAim for clarity of code over cleverness4/29/2010M. Campbell - 201014p. 12
CommentsPreceded by a 'Aim for comments to describe the programCan write the comments first (i.e. the logic) and then fill in the code afterwards4/29/2010M. Campbell - 201015p. 11
ModularityUse code modules to isolate repetitive codeHelps to shorten codeImproves readability of code4/29/2010M. Campbell - 201016p. 14
ModularityTwo types of code modules:Functions:Return a value when finishedSubroutines:Do not return a value upon finishingCollectively referred to as procedures4/29/2010M. Campbell - 201017p. 15

Chapter 2: Preliminaries