Simple Addition Program: Lab Report
Simple Addition Program: Lab Report
Program
Lab Report
Marco Abela
0411793(M)
B. Eng. (Hons.) in Mechanical Engineering
Lab Report 1
o start o!! the si"ple a##ition progra"$ the e%cel sprea#sheet is opene# an# the title$
basic a&thorship in!or"ation are 'ritten. (ells are set &p to sho' the !irst an# secon#
n&"bers an# their total. o 'rite the )BA "acro that 'o&l# per!or" this a##ition$ the )BE
is opene# &sing the shortc&t Alt * +11. A ne' "o#&le is inserte# into the )BE$ on 'hich the
"acro is to be 'ritten b, right-clic.ing$ choosing insert an# clic.ing "o#&le.
B, t,ping in /s&b A##er0 an# pressing enter$ a ne' s&bro&tine proce#&re calle#
A##er is starte# b, )BE itsel! 'hich 'o&l# beco"e the a##ition "acro. 1nsi#e the
s&bro&tine$ the progra" co#e is t,pe#. o start o!!$ a 2MsgBo%3 co""an# is &se# to #ispla, a
pop-&p stating the "acro3s &se. his is !ollo'e# b, a set o! instr&ctions &se# to inp&t #ata to
the progra". B, &sing the 2.4elect3 co""an#$ 4heet 1 !ro" the 'or.boo. is selecte#
!ollo'e# b, the cell B7$ 'here the !irst n&"ber chosen 'ill be #ispla,e#. 2a 5 )al(1np&tBo%3
is &se# to assign a 6al&e to the 6ariable a$ #eter"ine# b, 'hat is 'ritten in the inp&t bo% that
'ill pop-&p as.ing ,o& to enter the !irst n&"ber to be a##e#. his 6al&e is then #ispla,e# in
the cell B7 b, &sing the 2Acti6e(ell.)al&e 5 a3. his process is repeate# !or a secon# n&"ber
#ispla,e# in the cell B7 this ti"e. here!ore$ the cell B7 is selecte#$ an inp&t bo% pops &p
as.ing ,o& to enter the secon# n&"ber$ an# this is store# in a 6ariable b 'hilst also being
#ispla,e# in the cell B7.
he calc&lations section o! the "acro creates a ne' 6ariable 2c3$ s&ch that it 'ill be
e8&al to the a##ition o! the 6ariables 2a3 an# 2b3. his is #one &sing the co""an# 2c 5 a * b3.
he last part o! the co#e is to resen# the calc&late# in!or"ation bac. to the sprea#sheet an#
#ispla, it. he cell B10 is selecte# as the cell 'here the total 'ill be #ispla,e#. his is #one
9&st li.e the selection process !or the other cells. he cell B10 is assigne# the 6ariable 2c3 9&st
as abo6e again$ so that the total o! the a##ition o! the : n&"bers is #ispla,e# in cell B10. A
2MsgBo%3 co""an# is &se# to state the total 6al&e o! the t'o n&"bers. 4ince the total is a
6ariable an# is #i!!erent accor#ing to the 6al&es o! the 6ariables 2a3 an# 2b3$ the 2;3 s,"bol is
&se# to #enote the entr, o! a 6ariable into the "essage bo%.
he 'hole "acro consists o! those 3 parts< to retrie6e #ata !ro" the sprea#sheet$
per!or" a calc&lation$ an# sen# the ans'er bac. to the sprea#sheet. (4ee +ig&re 1) =hat is
le!t no' is to create a b&tton that allo's the "acro to be r&n 9&st b, a si"ple clic.. +ro" the
#e6eloper tab in Microso!t E%cel< 1nsert (o""an# b&tton. An a#e8&ate si>e o! the b&tton
is chosen &sing a clic. an# #rag. he b&tton is rena"e# to R?@ b, right-clic.ing on it$
choosing (o""an#B&tton Ab9ect an# clic.ing E#it. he onl, thing le!t is to assign the
s&bro&tine A##er to the b&tton so that 'hen it is clic.e#$ the "acro is la&nche#. he b&tton is
#o&ble-clic.e# 'hilst in #esign "o#e so that its co#e 'ill be opene# &p in the )BE. he
co""an# 2(all A##er3 is 'ritten so that 'hen la&nche#$ the b&tton 'ill call &p the s&bro&tine
na"e# A##er$ 'hich in this case is the si"ple a##ition progra" 9&st 'ritten. (4ee +ig&re :)
he progra" is !inishe# as s&ch. Ance #esign "o#e is 8&it$ the b&tton can be clic.e#
'hich in t&rn 'ill la&nch the "acro$ a##ing &p an# #ispla,ing t'o chosen n&"bers along
'ith their total. (4ee +ig&re 3)
Figure 1: Simple Addition Program Code. (Subroutine Adder)
Figure 2: Program Code for RUN !utton.
Figure ": #nd re$ult of program.