BMGT%302%Designing%Business%Applica5ons%

Lecture%01%
Overview%of%Computers%and%Programming%

!

DR. ADAM LEE
adamlee@rhsmith.umd.edu

!

Understanding%Computer%Systems%
! Combina5on%of%all%the%components%required%to%process%
and%store%data%using%a%computer%
! Hardware%–%equipment%or%physical%devices%associated%with%
a%computer%
•  Keyboard,%mouse,%screen,%hard%drive,%DVDNROM,%etc.%

! SoQware%(or%programs)%–%computer%instruc5ons%that%tell%
the%hardware%what%to%do%
•  System%soQware:%Windows,%Mac%OS%X,%Linux,%Unix,%DOS,%etc.%
•  Applica5on%soQware:%word%processing,%%spreadsheet,%media%player,%
scien5fic%compu5ng,%video%game,%eNmail%client,%web%browser,%etc.%

Lee%302%Ch.0"

1"

!

Computer%Organiza5on%–%Hardware%
! Input%unit%
•  Obtain%informa5on%from%various%input%devices%
•  Mouse,%keyboard,%microphone,%scanner,%etc.%

! Output%unit%
•  Takes%informa5on%that%the%computer%has%processed%and%places%it%
on%various%output%devices%
•  Screen,%printer,%speaker,%etc.%

! Memory%unit%
•  Where%computer%stores%data%temporarily%while%an%applica5on%is%
running%
•  RapidNaccess,%rela5vely%lowNcapacity,%vola5le%
•  RandomNaccess%memory%(RAM)%
Lee%302%Ch.0"

2"

!

% Lee%302%Ch.%CDNROM%drive.Computer%Organiza5on%–%Hardware% ! Central%Processing%Unit%(CPU)% •  The%brain%of%a%computer.%supervising%opera5ons%of%all%other% sec5ons%of%computer% •  Carries%out%the%instruc5ons%of%a%computer%program% ! Secondary%Storage%Unit% •  LongNterm%data%storage.0" 3" ! .%less%expensive% •  Slower%access%speed.%highNcapacity.%USB%memory.%etc.%DVDNROM%drive.%nonNvola5le% •  Hard%drive.

%C++.0" 4" ! .%etc.Computer%Programming% ! Programming% •  Write%computer%instruc5ons% ! Programming%language% •  Use%to%write%computer%programs% •  Visual%Basic.% ! Language%syntax% •  Rules%governing%its%word%usage%and%punctua5on% •  You%have%to%be%perfectly%accurate%when%talking%to%a%computer!!!% •  “How%the%geet%too%store%do%I?”% Lee%302%Ch.%Python.%C#.%Java.

%leders.%and%movies.% %NNN%Hal$Abelson.Inside%Computers%–%Bits%and%Pieces% ! Your%computer%successfully%creates%the%illusion%that%it% contains%photographs.%songs.%All%it% really%contains%is%bits.$Ken$Ledeen.%Your%computer%was%designed%to%store%just%bits%N% all%the%files%and%folders%and%different%kinds%of%data%are% illusions%created%by%computer%programmers.%lots%of%them.0" 5" ! .$in$“Blown$to$Bits”% Lee%302%Ch.%paderned%in%ways%you% can't%see.$Harry$Lewis.

Data%Representa5on%in%Computers% ! Computers%are%full%of%zillions%of% bits%that%are%either%on%or%off% •  1%if%the%bit%is%on% •  0%if%the%bit%is%off% ! Decimal%numeral%system% •  123%=%1×102%+%2×101%+%3% ! Binary%numeral%system% •  1011%=%1×23%+%0×22%+%1×21%+%1% =%11%(decimal)% Lee%302%Ch.0" 6" ! .

com% Unicode" Lee%302%Ch.Data%Representa5on%in%Computers% ! Symbols"as"Bits"–" ASCII"Characters" •  1%Byte%=%8%bits% •  American%Standard%Code%for% Informa5on%Interchange%(ASCII)% standard% •  www.0" 7" ! .asciitable.

0" 8" ! .% the%color%values%of%a%column% of%pixels%are%set%to%the%desired% color%of%the%line% Lee%302%Ch.Data%Representa5on%in%Computers% ! Graphics" •  computer's%display%consists%of% a%bunch%of%colored%points% called%pixels% •  It%has%a%posi5on%(its% coordinates)%which%consists%of% the%row%and%column%it%is%at% •  to%display%a%thin%ver5cal%line.

Programming%Language% !  Machine%language% •  MicroNprocessor’s%language% •  Write%instruc5ons%in%terms%of%binary%numbers% •  Too%hard%to%use% !  Assembly%language% •  the%opera5ons%that%the%microprocessor%knows%how%to%do%are%given% symbolic%names% •  Addresses%in%memory%are%also%given%meaningful%names% •  Translator%programs%called%assemblers%convert%assembly%language%into% machine%language% Lee%302%Ch.0" 9" ! .

Programming%Language% ! High%level%language% •  Enable%programmers%to%write%instruc5ons%that%look%like%everyday% English%and%contains%common%mathema5cal%nota5ons% •  Example:%grossPay%=%basePay%+%overTimePay% •  Translator%programs%called%compilers%convert%high%level%language% programs%into%machine%language% Lee%302%Ch.0" 10" ! .

From%Source%Code%to%Executable% proprietary%vs.%open%source%soQware% Lee%302%Ch.0" 11" ! .

%express%it%as%an% algorithm.Problem%Solving%and%Algorithm% ! It%has%oQen%been%said%that%a%person%does%not%really% understand%something%un5l%he%teaches%it%to%someone%else.%i.”% NNN%Donald$Knuth.% Actually%a%person%does%not%really%understand%something% un5l%aQer%teaching%it%to%a%computer.e.0" 12" ! ..$in$"American$Mathema<cal$Monthly”$1981% Lee%302%Ch.

0" 13" ! .Algorithm%% ! Algorithm:%an%ordered"sequence"of%unambiguous%and% well%defined"instrucLons"that%performs"some"task"and% halts"in"finite"Lme"" ! Example% •  baking%a%cake% Get%a%bowl% Add%three%cups%of%flour% Add%two%eggs% Add%a%cup%of%budermilk% S5r%% Bake%at%350%degrees%for%45%minutes% Lee%302%Ch.

0" 14" ! .How%to%Represent%Algorithms% ! Pseudocode% •  An%EnglishNlike%representa5on%of%a%numbered%list%of%instruc5ons%to% perform%some%task% ! Flowchart% •  A%pictorial%representa5on%of%the%logical%steps% Lee%302%Ch.

0" 15" ! .Pseudocode%–%Sequence%Control% Lee%302%Ch.

Pseudocode%–%Condi5onal/Selec5on%Control% Lee%302%Ch.0" 16" ! .

0" 17" ! .Pseudocode%–%Itera5ve/Loop%Control% Lee%302%Ch.

Lee%302%Ch.0" 18" ! .

Flowchart %% Lee%302%Ch.0" 19" ! .

Flowchart%–%Examples%% Lee%302%Ch.0" 20" ! .

Flowchart%–%Sequence%Control% Lee%302%Ch.0" 21" ! .

0" 22" ! .Flowchart%–%Condi5onal/Selec5on%Control% Lee%302%Ch.

0" 23" ! .Flowchart%–%Itera5ve/Loop%Control% Lee%302%Ch.

ADAM LEE adamlee@rhsmith.BMGT%302%Designing%Business%Applica5ons% Lecture%02% Chapter%1%–%Introduc5on%to%Visual%Basic%2010% ! DR.edu ! .umd.

1+ 1+ ! .%close%and%open%an%exis5ng%solu5on% ! Find%and%correct%a%syntax%error% Lee#302#Ch.Objec5ves% ! Create%a%Visual%Basic%2010%WindowsGbased%applica5on% ! Manage%the%windows%in%the%Integrated%Development% Environment%(IDE)% ! Set%the%proper5es%of%an%object% ! Add%a%control%to%a%form% ! Enter%code%in%the%Code%Editor%window% ! Start%and%end%an%applica5on% ! Write%an%assignment%statement%% ! Save.

NET%placorm%and%VB.1+ 2+ ! .A%LiRle%History% ! Visual%Basic%is%evolved%from%BASIC+ •  Beginner’s%AllGpurpose%Symbolic%Instruc5on%Code% •  Designed%by%Prof.%John%George%Kemeny%and%Thomas%Eugene%Kurtz% at%Dartmouth%College%–%1964% •  Bill%Gates%implemented%BASIC%on%personal%computers%–%1975% •  Microso_%Windows%graphical%user%interface%(GUI)%–%1985% •  Visual%Basic%–%1991% •  VBScript%–%1996% •  .NET%–%2001% Lee#302#Ch.

% Lee#302#Ch.1+ 3+ ! .Understanding%User%Environment% ! CommandGline%environment% •  A%commandGline%interface%(CLI)%is%a%mechanism%for%interac5ng%with% a%computer%opera5ng%system%or%so_ware%by%typing%commands%to% perform%specific%tasks.% •  Applica5ons%are%called%console%applica5ons.

% % We%will%in%this%class%focus%on% Windows%Form%Applica5ons.1+ 4+ ! .% Applica5ons%are%called% Windows%Form%Applica5ons.% •  Other%components.% •  Graphical%images%to%guide%a%system%user%in%using%the%program.Understanding%User%Environment% ! Graphical+user+interface+(GUI)+ •  BuRons%(some%with%icons%and%graphical%images)%and%menus%on% which%you%point%and%click.% Lee#302#Ch.% •  Textbox%controls%in%which%you%type%informa5on.

% •  Runs%on%a%server.% Lee#302#Ch.Understanding%User%Environment% ! WebGbased%applica5on:%% •  Has%a%Web%user%interface.% •  Accessed%with%a%computer%browser.1+ 5+ ! .

%%Example%events%include:% •  Clicking%a%buRon%or%menu% •  Opening%or%closing%a%form% •  Select%an%item%in%a%list%box% •  Type%keyboard%to%input%text%% Lee#302#Ch.1+ 6+ ! .Visual%Basic% ! Is%an%event%driven)programming)language%because%you% will%write%program%code%that%responds%to%events%that%are% controlled%by%the%system%user.

% •  Means%you%work%with%objects%in%building%an%applica5on.%ListBox% objects.Visual%Basic% ! is%an%object%oriented)programming)language.% •  Object:+anything%that%can%be%seen.%PictureBox%objects..%e.g.%object%is%said%to%be% instanEated+ Lee#302#Ch.%Label%objects.%and%more.%touched.%Form% objects.%TextBox%objects.%BuRon%objects.1+ 7+ ! .%or%used% •  Class:%a%paRern%used%to%create%an%object% •  Instance:%an%object%created%from%a%class.

1+ 8+ ! .%color.%turn%right.%year.ObjectGOriented%Programming% ! What%defines%an%object% •  Sta5c%characteris5cs%–%ProperEes+ Ex:%a%car%has%make.%turn%le_.%transmission%type% "  Ex:%a%buRon%has%Text%property%and%Name%property% "  •  Dynamic%characteris5cs%–%Methods+ "  Ex:%a%car%can%accelerate.%a%textBox%can%respond%to% TextChanged%event% Lee#302#Ch.%model.%engine%type.%back%up% •  Ac5ons%to%which%an%object%can%respond%–%Events+ "  Ex:%a%buRon%can%respond%to%click%event.

%Visual+C#%(C%sharp).1+ 9+ ! .% ! All%of%these%languages%compile%% •  This%means%they%are%translated%from%human%readableGform%to% machine%readableGform%GG%to%the%same%Microso_%Intermediate% Language%(MSIL).% Lee#302#Ch.NET%Framework% ! .NET%introduced%a%unified%programming%environment% •  Visual+Basic.%%% ! MSIL%run%within%the%Common+Language+RunEme%(CLR)%% •  A%component%of%the%.NET%Framework.Microso_%.NET).%Visual+F#%(F%sharp)%and%Web% Development%(called%ASP.

%hRp://msdn.Visual%Studio% ! Integrated+Development+Environment+(IDE)+ •  So_ware%package%that%provides%an%editor.NET+Framework+Class+Library.% ! Visual%Studio%is%an%IDE.% •  MSDN+(Help).%%This%component%manages%the% execu5on%of%a%programming%project%wriRen%in%any%of%the% languages%that%are%included%within%Visual%Studio%including%Visual% Basic.% •  Common+Language+RunEme+(CLR).%compiler.1+ 10+ ! .%run%and%test%your% programs.%%This%is%the%help%component%and%provides%access%to%a% help%reference%library.%%This%is%a%library%of%predefined%class% objects.%and%has% •  .%and%other% programming%tools%that%help%you%to%create.microso_.com/% Lee#302#Ch.

How%to%obtain%Visual%Studio%
! Use%Visual%Studio%in%the%labs%
! Download%free%Visual%Basic%2010%Express%
•  hRp://www.visualstudio.com/downloads/downloadGvisualGstudioG
vs#DownloadFamilies_4%

! Obtain%Visual%Studio%2010%Professional%
•  Through%Microso_%DreamSpark%
•  Free%for%student%(use%your%@umd.edu%address%for%verifica5on)%
•  hRps://www.dreamspark.com/default.aspx%

Lee#302#Ch.1+

11+

!

Figure%1G1%Using%Microso_%Visual%Studio%
! Windows%applica5ons%
consist%of%solu5ons,%
projects,%and%files%
! SoluEon:%a%container%that%
stores%projects%and%files%
for%an%en5re%applica5on%
! Project:%a%container%that%
stores%files%associated%
with%a%specific%por5on%of%
the%solu5on%
! A%solu5on%may%contain%
one%or%more%projects%
Lee#302#Ch.1+

12+

!

Figure%1G2%Star5ng%Microso_%Visual%Studio%

Lee#302#Ch.1+

13+

!

1+ 14+ ! .Figure%1G3%VS%2010%Professional%Startup%Screen% Lee#302#Ch.

1+ 15+ ! .Figure%1G4%VB%2010%Express%Startup%Screen% Lee#302#Ch.

1+ 16+ ! .Figure%1G5%VB%2010%Windows%Applica5on% Lee#302#Ch.

Figure%1G5%VB%2010%Windows%Applica5on% Lee#302#Ch.1+ 17+ ! .

Figure%1G7%New%Project%Dialog%Box%in%VS%2010% Lee#302#Ch.1+ 18+ ! .

1+ 19+ ! .Figure%1G8%New%Project%Dialog%Box%in%VB%2010% Lee#302#Ch.

1+ 20+ ! .Figure%1G9%VB%2010%Project% Lee#302#Ch.

Figure%1G10%Managing%Windows%in%the%IDE% Lee#302#Ch.1+ 21+ ! .

1+ 22+ ! .vb+[Design]+ Lee#302#Ch.Figure%1G11%Windows%Form%Designer%Window% ! Allows%you%to%create%(design)% the%GUI% ! Windows+Form+object%(or% form):% •  Founda5on%for%the%user%interface% •  Add%other%objects%such%as% buRons%to%form% •  Title%bar%with%capEon%and% Minimize.%and%Close% buRons% •  Tab%at%top%of%designer%window% has%Form1.%Maximize.

Figure%1G12%Solu5on%Explorer%Window% ! Displays%a%list%of%projects% contained%in%this%solu5on% ! Displays%the%items% contained%in%each%project% ! Source+file:%a%file%containing% program%instruc5ons% ! Code:%program%instruc5ons% ! Form+file:%a%file%containing% code%associated%with%a% Windows%form% Lee#302#Ch.1+ 23+ ! .

Figure%1G13%Proper5es%Window% •  ProperEes:%a%set%of%aRributes%that%determine%an%object’s% appearance%and%behavior+ •  Default%property%values%are%assigned%when%an%object%is% created% •  Includes an Object box and a Properties list Lee#302#Ch.1+ 24+ ! .

Figure%1G14%Proper5es%of%a%Windows%Form% ! Class+definiEon:%block%of%code% defining%aRributes%and%behaviors% of%an%object% ! Namespace:%defines%a%group%of% related%classes% ! Dot+member+access+operator:%the% period%separa5ng%words%in%an% object’s%name%to%indicate%a% hierarchy%of%namespaces% ! Name+property% ! Text%property% ! StartPosiEon%property% ! Font+property% Lee#302#Ch.1+ 25+ ! .

%moved.1+ 26+ ! .%locked%in% place%on%the%form%and%unlocked% Lee#302#Ch.%can%be%created% ! Controls:%% •  Objects%displayed%on%a%form% •  Represented%as%icons%in%the%toolbox% ! Controls%on%a%form%can%be%selected.%called%controls.% sized.%such%as%a%form% •  Each%tool%has%an%icon%and%a%name%to% iden5fy%it% •  Each%tool%represents%a%class%from%which% objects.Figure%1G15%Toolbox%Window% ! Toolbox:%% •  Contains%objects%that%can%be%added%to% other%objects.%deleted.

Figure%1G18%Label.%Picture%Box%and%BuRon% Controls% Lee#302#Ch.1+ 27+ ! .

1+ 28+ ! .Figure%1G19%&%1G20%Using%Code%Editor%Window% Lee#302#Ch.

Code%Editor%Window% ! Class%statement:%used%to%define%a%class% •  Begins%with%Public Class <class name>% •  Ends%with%End Class ! Class+Name+list+box:%lists%the%names%of%objects%(controls)% included%in%the%user%interface% ! Method+Name+list+box:%lists%the%events%to%which%the% selected%object%is%capable%of%responding% ! Syntax:%rules%of%the%language% ! Keyword:%a%word%with%special%meaning%in%a%programming% language% Lee#302#Ch.1+ 29+ ! .

close() ! Me.Close()+instrucEon:%closes%the%current%form%at%run%5me% ! Me%keyword:%refers%to%the%current%form% ! Method:%predefined%VB%procedure%that%can%be%invoked% (called)%when%needed% Lee#302#Ch.Exit%Form%Using%Me.1+ 30+ ! .

Assigning%Value%to%a%Property%During%Run%Time% ! ProperEes%window%is%to%set%property%values%at%design%5me% ! Assignment+statement:%assigns%a%value%to%a%variable%or% property%of%a%control%(at%run%5me)% ! String:%zero%or%more%characters%enclosed%in%“”%marks% ! Assignment+operator:%the%=%sign% •  Value%of%the%expression%on%the%right%of%the%=%sign%is%assigned%to%the% object%and%property%on%the%le_%of%the%=%sign.% Lee#302#Ch.1+ 31+ ! .

Figures%1G33%&%1G34%Coding%Errors %% ! Bug:%an%error%in%a%program’s%code+ ! Debugging:%the%process%of%loca5ng%and%correc5ng%bugs%in%a% program+ ! Syntax+error%and%IntelliSense% % ! VB%lists%errors%in%the%View%menu%#%Error+List+window% Lee#302#Ch.1+ 32+ ! .

Errors%in%Programs% ! Syntax+error+ •  Errors%in%coding%which%do%not%follow%language%syntax%format.% •  Such%error%cause%a%program%to%end%abruptly%or%even%cause%system% shutGdown.+ ! Logical+error+ •  Syntax%is%correct.+ Lee#302#Ch.% •  It%can%occur%by%human%mistake%in%typing%or%due%to%a%lack%of% knowledge%of%a%language.1+ 33+ ! .%program%will%execute%properly%but%not%give% answer%correct.+ ! RunEme+error+ •  Run5me%Error%occurs%at%run5me.

BMGT%302%Designing%Business%Applica5ons% Lecture%03% Chapter%2%–%Designing%User%Interface% ! DR. ADAM LEE adamlee@rhsmith.umd.edu ! .

2" 1" ! .Objec5ves% ! Plan%an%applica5on%using%a%TOE%chart% ! Use%text%boxes%and%containers% ! Assign%access%keys%to%controls% ! Set%the%tab%order% ! Add%a%splash%screen%to%a%project% ! Use%the%Font%and%Color%dialog%boxes% ! Designate%a%default%buLon% ! Print%the%interface%during%run%5me% Lee%302%Ch.

"Event)"chart:% •  Shows%applica5on’s%tasks."Object.2" 2" ! .Figure%2N1%Planning%an%Applica5on% ! Plan%the%applica5on%before%crea5ng%the%user%interface% ! Work%jointly%with%the%user%to%ensure%the%success%of%the% applica5on% ! TOE"(Task.%and%events% Lee%302%Ch.%objects.

Sunshine%Cellular%Company% ! Sunshine%Cellular%Company:% •  Takes%orders%by%phone%for%cell%phones% •  Two%colors:%blue%and%silver%($100%each)% •  Currently%the%salespeople%calculate%the%order%quan5ty%and%order% total%(including%sales%tax)% ! Develop%an%orderNtaking%applica5on%for%this%company% Lee%302%Ch.2" 3" ! .

Figure%2N2%Iden5fying%the%Applica5on’s%Tasks% ! Current%paper%order%form%used%by%Sunshine%Cellular:% Lee%302%Ch.2" 4" ! .

Figure%2N3%Tasks%Entered%into%a%TOE%Chart% Input% Processing% Output% Other% Lee%302%Ch.2" 5" ! .

%such%as%to%calculate%totals.2" 6" ! .Iden5fying%the%Objects% ! Assign%each%task%to%an%object%in%the%user%interface% ! Text"box:"a%control%that%allows%the%user%to%enter%data% ! Use%labels%to%guide%the%user%and%display%output% informa5on% ! Use%buBons%to%perform%ac5ons%immediately%aYer%user% clicks.%to%clear%the%screen%and%to% end%the%applica5on% Lee%302%Ch.

Figure%2N4%Objects%Entered%into%a%TOE%Chart% Lee%302%Ch.2" 7" ! .

2" 8" ! .Iden5fying%the%Events% ! Next.%determine%which%objects%need%an%event%to%occur%to% allow%the%object%to%perform%its%task% ! Text%boxes:%no%special%events%needed%for%user%to%enter%the% text% ! Labels:%no%special%events%needed%to%display%the%prompts% ! BuLons:%ac5on%must%occur%when%each%buLon%is%clicked% Lee%302%Ch.

2" 9" ! .Figure%2N5%Completed%TOE%Chart%Ordered%by% Task% Lee%302%Ch.

2" 10" ! .Figure%2N6%Completed%TOE%Chart%Ordered%by% Object% Lee%302%Ch.

2" 11" ! .Designing%the%User%Interface% ! Next%step%is%to%design%the%user%interface% ! Follow%Windows%GUI%guidelines%for:% •  Consistency%with%Windows%standards% •  Ease%of%use% •  Familiar%look%and%feel%makes%the%applica5on%easier%to%learn% Lee%302%Ch.

Arranging%the%Controls%on%a%Form% ! Design%guidelines:% •  Informa5on%should%flow%either%ver5cally%or%horizontally% •  Most%important%informa5on%should%be%in%upperNleY%corner%of%the% screen% •  Group%related%controls%together%using%white%space%or%container% controls% ! Container%controls%include:% •  Group"box"control" •  Panel"control" •  Table"layout"panel"control" Lee%302%Ch.2" 12" ! .

2" 13" ! .Figure%2N7%Arranging%the%Controls%–%Ver5cal% Arrangement% Lee%302%Ch.

Figure%2N8%Arranging%the%Controls%–%Horizontal% Arrangement% ! Group%Box:%has%Text%Property%% ! Panel:%can%have%scroll%bars% ! Table%Layout%Panel:%table%structure% Lee%302%Ch.2" 14" ! .

2" 15" ! .Arranging%the%Controls% ! Label%guidelines:% •  Use%a%label%to%iden5fy%each%text%box% •  LeYNalign%the%label’s%text% •  Posi5on%label%to%leY%of%or%above%the%text%box%it%iden5fies% •  Labels%and%buLon%cap5ons%should%be%one%to%three%words%only%and% appear%on%one%line% •  Labels%and%cap5ons%should%be%meaningful% •  An%iden5fying%label%should%include%a%colon%(:)% •  Use%sentence%capitaliza5on%for%iden5fying%labels% Lee%302%Ch.

Arranging%the%Controls%
! Sentence"capitalizaNon:%capitalize%first%leLer%in%first%word%
and%any%other%words%customarily%capitalized%
! Book"Ntle"capitalizaNon:%capitalize%first%leLer%in%each%word%
(except%ar5cles,%conjunc5ons,%and%preposi5ons)%
! BuLon%guidelines:%
•  Size%buLons%rela5ve%to%each%other%
" 
" 

If%posi5oned%horizontally,%same%height%
If%stacked%ver5cally,%same%width%also%

•  Most%commonly%used%buLon%should%be%first%
•  Use%book%5tle%capitaliza5on%for%buLons%
Lee%302%Ch.2"

16"

!

Borders%and%Sizing%of%Controls%
! BorderStyle"property:%determines%the%style%of%a%control’s%
border%
•  Seengs:%None,%FixedSingle,%Fixed3D%

! TextBox%should%be%set%to%Fixed3D%
! Iden5fying%labels%should%be%set%to%None%%
! Labels%that%display%output%should%be%set%to%FixedSingle%
! AutoSize"property:%determines%if%a%label%control%
automa5cally%sizes%to%fit%its%current%contents%

Lee%302%Ch.2"

17"

!

Color%Proper5es%of%a%Control%
! ForeColor%
! BackColor%

Lee%302%Ch.2"

18"

!

2" 19" ! .Figure%2N9%Assigning%Access%Keys% ! Access"key:%% •  Allows%user%to%select% an%object%using%Alt%+% access%key% •  May%or%may%not% appear%underlined%on% the%control’s%text% "  Can%display%temporarily% or%hide%by%pressing%the% Alt%key% •  Is%not%case%sensi5ve% Lee%302%Ch.

Assigning%Access%Keys% ! Access%key%guidelines:% •  Assign%access%keys%to%each%control%that%can%accept%user%input%(such% as%text%boxes%and%buLons)% •  Each%access%key%should%be%unique% •  Follow%Windows%standards%for%choice%of%access%keys% ! Include%&%in%front%of%the%character%to%be%used%as%the%access% key:% •  &Name%#%Name% •  &Calculate%Order%#%Calculate%Order% Lee%302%Ch.2" 20" ! .

Controlling%the%Tab%Order% ! TabIndex"property:%% •  Determines%the%order%in%which%a%control%receives%the%focus%when% the%Tab%key%is%pressed% •  Starts%at%0% •  Assigned%by%default%as%the%order%in%which%controls%are%added%to%the% form%at%design%5me% •  Should%be%set%to%the%order%in%which%the%user%will%want%to%access%the% controls% ! Focus:%the%state%of%being%able%to%accept%user%input% ! Set%TabIndex%using%the%Proper5es%window%or%the%Tab% Order%op5on%on%the%View%menu% Lee%302%Ch.2" 21" ! .

Figure%2N11%Seeng%the%TabIndex%Property% Lee%302%Ch.2" 22" ! .

2" 23" ! .Figure%2N12%Seeng%the%TabIndex%Property% Lee%302%Ch.

Splash%Screens% ! Splash%screen:%appears%when%an%applica5on%is%started% ! Used%to%introduce%the%applica5on% ! Used%to%hold%the%user’s%aLen5on%while%the%program%is% being%loaded%into%memory% Lee%302%Ch.2" 24" ! .

2" 25" ! .%Maximize.%and%closed%by%the%user% ! Primary%window’s%5tle%bar%includes:% •  Minimize.Primary%Window%and%Dialog%Boxes% ! Primary"window:%a%main%window%that%can%be%resized.% minimized.%maximized.%and%Close%buLons%on%the%right% •  Control%menu%on%the%leY% ! Dialog%boxes%can%be%closed%only% ! Dialog%box’s%5tle%bar%includes:% •  Close%buLon%and%op5onally%a%Help%buLon% •  No%control%menu% Lee%302%Ch.

2" 26" ! .Figure%2N21%Primary%Window%and%Font%Dialog% Box% Lee%302%Ch.

2" 27" ! .Dialog%Boxes% ! Use%tools%in%the%Dialogs%sec5on%of%the%toolbox%for% commonly%used%dialog%boxes:% •  Color% •  Font% •  Save%As% ! These%controls%do%not%appear%on%the%form% •  They%are%placed%in%the%component%tray%in%the%IDE% ! Component%tray%stores%controls%that%do%not%appear%in%the% user%interface%during%run%5me.%you%can%write%code%to%open% these%controls%in%response%to%an%event% Lee%302%Ch.

%on%the%other%hand.%allows%the%user%to% switch%focus%to%anther%form%while%it%is%displayed% Lee%302%Ch.Dialog%Boxes% ! Dialog%boxes%are%modal% •  They%remain%on%the%screen%un5l%the%user%closes%the%dialog%box% •  No%input%from%keyboard%or%mouse%can%occur%in%the%primary% window%un5l%the%dialog%boxes%is%closed% ! A%modeless%form.2" 28" ! .

2" 29" ! .Dialog%Boxes% ! Default"buBon:%ac5vated%when%user%presses%Enter%key% when%the%buLon%does%not%have%the%focus% ! Cancel%buBon:%ac5vated%when%user%presses%Esc%key%when% the%buLon%does%not%have%the%focus% ! Most%dialog%boxes%have%a%default%buLon%and%a%cancel% buLon%specified% Lee%302%Ch.

2" 30" ! .Figure%2N26%Color%Dialog%Box%with%Default%and% Cancel%BuLons% Lee%302%Ch.

Designa5ng%the%Default%and%Cancel%BuLon%on%a% Form% ! AcceptBuBon%property:%% •  A%form%property%that%designates%the%name%of%the%default%buLon% •  Only%one%per%form% •  Should%be%the%buLon%that%is%most%oYen%selected%by%the%user% (unless%the%tasks%performed%by%this%buLon%are%both%destruc5ve% and%irreversible)% ! Default%buLon%has%a%darkened%border%during%design%5me% and%run%5me% ! CancelBuBon"property:" •  A%form%property%that%designates%the%name%of%the%cancel%buLon% Lee%302%Ch.2" 31" ! .

2" 32" ! .Figure%2N27%Designa5ng%the%Default%BuLon%on% a%Form% Lee%302%Ch.

Prin5ng%an%Interface%During%Run5me% ! PrintForm%tool:%prints%an%interface%during%run5me% •  Contained%in%the%Visual%Basic%PowerPacks%sec5on%of%the%toolbox% •  Control%appears%in%the%Component%tray% ! Print"Preview"buLon%sends%output%to%the%Print%Preview% window% ! Print%buLon%sends%output%directly%to%the%printer% Lee%302%Ch.2" 33" ! .

2" 34" ! .Figure%2N28%Prin5ng%Interface%During%Run5me% Lee%302%Ch.

2" 35" ! .Figure%2N29%Code%to%Print%Interface%During% Run5me% Lee%302%Ch.

3* 5* ! .3* 1* ! Figure%3S1%Illustra7on%of%Storage%Bins% ! Internal*memory:%a%component%inside%a%computer% comprised%of%memory%loca7ons% ! Each%memory%loca7on%has%a%unique%numeric%address%and% can%hold%only%one%item%at%a%7me% ! A%programmer%can%reserve%memory%loca7ons%by%assigning% •  Name:%more%descrip7ve%words%instead%of%address% •  Data*type:%indicates%the%type%of%data%the%memory%loca7on%will% store% •  Ini9al*value* ! Two%types%of%memory%loca7ons%that%a%programmer%can% declare:%variables%and%constants% Lee#302#Ch.umd.edu ! Internal%Memory%% Lee#302#Ch.3* 3* ! Figure%3S2%Naming%a%Variable% ! Variables:%computer%memory%loca7ons%used%to% temporarily%store%data%while%an%applica7on%is%running% •  Contents%can%change%during%run%7me% ! Use%a%meaningful%variable*name*that%reflects%the%purpose% of%the%variable% ! Use%camel*casing*for%variable%iden7fiers% ! Variable%names%should%conform%to%naming%rules% Lee#302#Ch.3* 4* ! Lee#302#Ch. ADAM LEE adamlee@rhsmith.3* 2* ! Variables%% Lee#302#Ch.Objec7ves% BMGT%302%Developing%Business%Applica7ons% Lecture%04% Chapter%3%–%Variables%and%Calcula7ons% ! Declare%variables%and%named%constants% ! Convert%data%to%the%appropriate%type%using%the%TryParse% method%and%the%Convert%class%methods% ! Write%arithme7c%expressions% ! Understand%the%scope%and%life7me%of%variables%and%named% constants% ! Understand%the%purpose%of%the%Option%statements% ! Use%pseudocode%and%flowchart%to%code%an%applica7on% ! Clear%content%of%a%control’s%Text%property%during%run7me% ! Send%the%focus%to%a%control%during%run7me% ! DR.

%or%Static Name%of%the%variable%and%data%type% Ini7al%value%(op7onal)% Numeric%data%types:%automa7cally%ini7alized%to%0% String%data%type:%automa7cally%ini7alized%to%Nothing Boolean%data%type:%ini7alized%to%False Lee#302#Ch.3* 11* ! .3* 9* ! Figure%3S4%Declaring%a%Variable% 10* ! Lee#302#Ch.Data%Types% Unicode%and%Other%Data%Types% ! Each%variable%must%be%assigned%a%data*type.%Private.3* 8* ! Figure%3S4%Declaring%a%Variable% Lee#302#Ch.%a% variable% •  Declara7on%statement%includes:% "  "  floa7ngSpoint%numbers% achieve%their%greater% range%at%the%expense% of%precision% "  ! Ini7aliza7on% •  If%not%explicitly%ini7alized:% "  –  –  Lee#302#Ch.%which% determines%the%memory%loca7on’s%data%type.3* 6* "  ! Figure%3S3%Basic%Data%Types%in%Visual%Basic% Computer%must%determine%the%data%type%at%run%7me.3* 7* ! Declaring%a%Variable%in%Code% ! Declara9on*statement:%used%to%declare.3* Scope/life7me%keyword:%Dim.% ! Each%data%type%is%a%class%(OOP):% ! Unicode:%% •  Universal%coding%scheme%for%characters%that%assigns%a%unique% numeric%value%to%each%character% •  Integer.%making%it%more% inefficient% Lee#302#Ch.%or%create.%Double%and%Single%data%types:%store%real%numbers% •  Boolean%data%type:%stores%a%value%of%True%or%False •  Date%data%type:%stores%date%and%7me%informa7on% •  Object%data%type:%stores%any%type%of%data% (numbers%with%decimal%places)% •  Char%data%type:%stores%one%Unicode%character% •  String%data%type:%stores%mul7ple%Unicode%characters% Lee#302#Ch.%Long%and%Short%data%types:%store%integers%(whole% numbers)% ! Other%data%types% •  Decimal.

%object%proper7es.%keywords.%“650”%is%a%string%literal% •  “James”%is%a%string%literal.%or%arithme7c%operators% Lee#302#Ch.3* 14* ! Lee#302#Ch.3* 13* ! Figure%3S5%Assigning%a%Value%to%a%Variable% What%if%the% type%on%the% RHS%does%not% match%LHS% variable?% Lee#302#Ch.%the%method%stores% the%value%in%the%variable% ! If%unsuccessful.% variables.3* 16* ! Lee#302#Ch.Assigning%Data%to%an%Exis7ng%Variable% Assigning%Data%to%an%Exis7ng%Variable% ! Assignment*statement:% !  Literal*constant:%% •  An%item%of%data%whose%value%does%not%change%while%the%applica7on%is% •  Used%to%assign%values%to%proper7es%of%controls% •  Used%to%assign%values%to%variables% running% •  Can%be%a%numeric%(such%as%255)%or%a%string%literal%constant%(such%as% “James”)% ! Assignment*operator%(=):% !  A%numeric%literal%without%a%decimal%place%is%treated%as%an% Integer type% !  A%numeric%literal%with%a%decimal%place%is%treated%as%a%Double% type% !  String%literals%are%enclosed%in%quota7on%marks% •  Expression%on%the%right%of%the%=%operator%is%assigned%to%the% variable%on%the%le`%of%the%=%operator% ! Expression:%can%contain%literal%constants.3* 17* ! .3* 15* Using%the%TryParse()%Method% Using%the%TryParse()%Method% ! Method:%a%specific%por7on%of%a%class’%instruc7ons%that% performs%a%task%for%the%class% ! TryParse%()method%:%% ! If%TryParse%conversion%is%successful.%a%0%is%stored%in%the%numeric%variable% ! •  Part%of%every%numeric%data%type’s%class% •  Used%to%convert%a%string%to%that%numeric%data%type% ! Argument:%a%value%that%is%provided%to%a%method% ! Basic%syntax%of%TryParse%method%has%two%arguments:% •  String:%string%value%to%be%converted% •  Variable:%loca7on%to%store%the%result% •  Use%comma%to%separate%arguments% Lee#302#Ch.3* 12* •  650%is%a%numeric%literal.%James%(without%quota7on%marks)%is%a%variable% ! Figure%3S5%Assigning%a%Value%to%a%Variable% Lee#302#Ch.

3* 20* ! Including%Variables%in%Arithme7c%Expressions% Lee#302#Ch.%Decimal%and%Integer%Data%Types% ! Using%the%Convert()%Class%Methods% Lee#302#Ch.3* 18* Figure%3S7%Result%of%TryParse()%for%the% Double.3* 21* ! Figure%3S9%Most%Commonly%Used%Arithme7c% Operators% ! Arithme9c*operators:%used%to%perform%calcula7ons* ! Precedence*number:%indicates%the%order%in%which%an% opera7on%in%an%expression%is%performed% ! If%an%expression%has%two%operators%with%the%same% precedence.3* 22* ! Lee#302#Ch.%they%are%evaluated%from%le`%to%right% ! Use%parentheses%to%change%the%order%of%evalua7on% ! Integer*division*operator%(\):%divides%two%integers%and% returns%an%integer%value% ! Modulus*arithme9c*operator%(Mod):%divides%two%numbers% and%returns%the%remainder% Lee#302#Ch.Figure%3S6%Basic%Syntax%of%TryParse()% Lee#302#Ch.3* 19* ! Figure%3S8%Using%the%Convert()% ! Convert*class:% •  Contains%methods%for%conver7ng%numeric%values%to%specific%data% types% ! Commonly%used%methods%of%the%Convert%class%include:% •  ToDouble •  ToDecimal •  ToInt32 •  ToString Lee#302#Ch.3* 23* ! .

3* Lee#302#Ch.3* 28* ! Lee#302#Ch.3* 27* ! Figure%3S13%Using%Arithme7c%Assignment% Operators% ! Arithme9c*assignment*operators:%abbreviate%an% assignment%statement%that%contains%an%arithme7c% operator%for%specific%cases% ! Original%statement%must%be%of%the%form:% variableName = variableName arithmeticOperator value% ! Statement%using%arithme7c%assignment:% variableName arithmeticOperator= value Lee#302#Ch.3* 26* 25* ! Figure%3S12%Using%Variables%and%Arithme7c% Operators% ! Arithme7c%Assignment%Operators% Lee#302#Ch.Figure%3S10%Using%Integer%Division%and%Mod% Operators% Figure%3S11%Expressions%Containing%More%than% One%Operator%Having%the%Same%Precedence% Lee#302#Ch.3* S4*7S4=?% 24* ! Figure%3S12%Using%Variables%and%Arithme7c% Operators% Lee#302#Ch.3* 29* ! .

3* 35* ! ! .3* 31* 34* ! Lee#302#Ch.%or%block% scope% ! A%variable’s%scope%and%life7me%are%determined%by%where% you%declare%the%variable% •  Variables%declared%in%the%form’s%Declara7ons%sec7on%(outside%of% any%procedure)%have%class%scope% •  Variables%declared%within%a%procedure%have%either%procedure% scope%or%block%scope% Lee#302#Ch.3* ! •  Used%to%internally%document%the%procedure% •  Are%ignored%by%the%compiler% •  Appear%in%green%in%the%Code%Editor% ! Procedure*scope:%only%the%procedure%can%use%the%variable% Lee#302#Ch.% Lee#302#Ch.%comment%line%begins%with%an%apostrophe% % ! Life7me%of%ProcedureSlevel%variable:% •  Same%as%the%procedure%that%declares%it% 32* ! Lee#302#Ch.%two%procedures%can%each%use%the% same%variable%names% ! In%VB.%procedure%scope.3* 30* ! Lee#302#Ch.% •  To%con7nue%a%statement%to%the%next%line.Figure%3S13%Using%Arithme7c%Assignment% Operators% The%Scope%and%Life7me%of%a%Variable% ! Scope:%indicates%where%the%variable%can%be%used% ! Life9me:%indicates%how%long%the%variable%remains%in% memory% ! Variables%can%have%class%scope.%you%can%type%a%space% followed%by%an%underscore%character%(_)%to%indicate%that%the% statement%isn’t%complete.3* Variables%with%Procedure%Scope% Comments%in%Code% ! Procedure#level*variable:%declared%within%a%procedure% ! Comments*in*code:%% •  Use%the%Dim%keyword%in%the%declara7on% •  With%procedureSlevel%scope.3* 33* Line%Con7nua7on%% Implicit%Line%Con7nua7on% ! When%a%statement%in%VB%is%split%up%across%mul7ple%lines% ! The%VB%2010%compiler%and%code%editor%now%adds%support% for%what%is%called%implicit%line%con7nua7on%support%–%which% means%that%it%is%smarter%about%autoSdetec7ng%line% con7nua7on%scenarios.

3* 36* Figure%3S15%Using%ProcedureSLevel%Variables% ! Variables%with%Class%Scope% Lee#302#Ch.3* 40* ! Lee#302#Ch.3* 37* ! Figures%3S16%&%3S17%Using%a%ClassSLevel% Variable% ! Class*scope:*variable%can%be%used%by%all%procedures%in%the% form* ! Class#level*variable:** •  Declared in the form’s Declarations section (between Public Class…and End Class) •  Use Private keyword in declaration% ! Life7me:%ClassSlevel%variables%retain%their%values%un7l%the% applica7on%ends% Lee#302#Ch.3* 39* ! Figures%3S16%&%3S18%Using%a%Sta7c%Variable% ! Static variable: •  Procedure-level variable that remains in memory and retains its value even after the procedure ends •  Retains its value until the application ends (like a class-level variable). but can only be used by the procedure in which it is declared ! A static variable has: •  Same lifetime as a class-level variable •  Same scope as a procedure-level variable !  Declared using the Static keyword Lee#302#Ch.Figures%3S14%&%3S15%Using%ProcedureSLevel% Variables% Lee#302#Ch.3* 38* ! Sta7c%Variables% Lee#302#Ch.3* 41* ! .

% •  Enforces%that%all%variables%must%be%declared%before%being%used.% % ! Misspelling%a%variable%name%can%result%in%an%undeclared% variable%unless%Option Explicit%is%on.3* 44* ! Lee#302#Ch.%and%Op7on%Strict% ! Undeclared*variable:%a%variable%that%does%not%appear%in%a% declara7on%statement%(such%as%Dim)% ! Op9on*Infer*Off*statement:%ensures%that%every%variable%is% declared%with%a%data%type% •  Is%assigned%a%data%type%of%Object.3* 47* ! .3* 42* ! Lee#302#Ch.% ! Op9on*Explicit*On*statement% •  Appears%in%the%General%Declara7ons%sec7on%of%the%Code%Editor% window%(above%Public Class%statement).% ! •  Not%to%infer%a%memory%loca7on’s%data%type.3* 43* ! Figures%3S20%&%3S21%Using%a%Named%Constant% Lee#302#Ch.3* 45* Op7on%Explicit.%and%Op7on%Strict% Op7on%Explicit.% Lee#302#Ch.Named%Constants% Figure%3S19%Declaring%a%Named%Constant% ! Named*constant:%memory%loca7on%whose%value%cannot%be% changed%while%the%applica7on%is%running% •  Declared%using%the%Const%keyword% •  Good%programming%prac7ce%to%specify%the%data%type%as%well% •  Many%programmers%use%Pascal%case%for%named%constants% ! Literal*type*character:%forces%a%literal%constant%to%assume%a% specific%data%type% ! Named%constants%help%to%document%the%program%code% Class%level% constant% Lee#302#Ch.3* 46* ! Lee#302#Ch.%Op7on%Infer.%Op7on%Infer.

%use%Op7on%Strict%On.%and%Op7on%Strict% Op7on%Explicit.2% To%prevent%trunca7on.Op7on%Explicit.3* 48* ! Figure%3S22%Rules%and%Examples%of%Type% Conversions%with%Option Strict On Lee#302#Ch.% Dim%score%As%Integer%=%3.* "  "  "  Can%cause%trunca7on%and%loss%of%precision.% "  Dim%sales%As%Double%=%453% •  If%converted%to%a%data%type%that%can%store%only%smaller%numbers.% the%value%is%said%to%be%demoted%(or%to%a%narrower%type).% resul7ng%in%lost%precision% •  If%converted%to%a%data%type%that%can%store%larger%numbers.% Lee#302#Ch.%the% value%is%said%to%be%promoted*(or%to%a%wider%type).% Lee#302#Ch.3* 53* ! .%Op7on%Infer.3* Run7me%Errors% Handling%Excep7ons% ! We’ve%seen%possible%run7me%errors:% !  Visual%Basic%provides%an%excep7on%handler% !  The%TrySCatch%statement:% •  OverFlowExcep7on% 51* ! There%are%many%others% •  DivideByZeroExcep7on% •  InvalidCastExcep7on% •  and%so%on% ! A%run7me%error%results%when:% •  Visual%Basic%throws%an%excep7on% •  And%it%is%an%unhandled%excep7on% !  The%try%block%contains%program%statements%that%might%throw%an% excep7on% !  The%catch%block%contains%statements%to%execute%if%an%excep7on% is%thrown% ! Cause%a%program%to%halt%abruptly% ! Excep7on%handling%allows%a%program%to%fail%gracefully%and% recover%if%possible.3* 49* ! Figure%3S23%Op7on%Statements%Entered%in%the% General%Declara7ons%Sec7on% ! Lee#302#Ch.3* 50* Lee#302#Ch.3* 52* ! Lee#302#Ch.%and%Op7on%Strict% ! Implicit*type*conversion:%occurs%when%you%arempt%to% assign%data%of%one%type%to%a%variable%of%another%type% without%explicitly%aremp7ng%to%convert%it% ! Op9on*Strict*On*statement:%ensures%that%values%cannot%be% converted%from%one%data%type%to%a%narrower%data%type.%Op7on%Infer.

3* 54* ! Lee#302#Ch.% Lee#302#Ch.%the%try%block%catches%it.Excep7on%Handling%Example% % ! If%CDec%throws%a%cast%excep7on.3* 55* ! .% jumps%to%and%executes%the%catch%block%which%displays%the% error%message.

edu ! .BMGT302(Designing(Business(Applica5ons( Lecture(05( Chapter(4(–(Selec5on(Structure( ! DR.umd. ADAM LEE adamlee@rhsmith.

4+ 1+ ! .Objec5ves( ! Explain(the(difference(between(singleIalterna5ve(and(dualI alterna5ve(selec5on(structures( ! Code(a(selec5on(structure(using(If…Then…Else( statement( ! Include(comparison(operators(and(logical(operators(in(a( selec5on(structure’s(condi5on( ! Create(a(blockIlevel(variable( ! Concatenate(strings( ! Change(the(case(of(a(string( ! Include(check(box(in(an(interface( ! Generate(random(numbers( Lee#302#Ch.

4+ 2+ ! .The(Selec5on(Structure( ! Selec0on+structure((or(decision+structure):( •  A(decision(need(to(be(made(based(on(the(outcome(of(a(condi5on( or(comparison( ! Condi0on:(( •  Upon(which(the(decision(will(be(made( •  Results(in(a(Boolean((True(or(False)(answer( Lee#302#Ch.

The(Selec5on(Structure( ! Single#alterna0ve+selec0on+structure:(performs(a(set(of( tasks(only(when(the(condi5on(is(true( ! True+path:(the(tasks(to(perform(when(the(condi5on(is(true( ! Dual#alterna0ve+selec0on+structure:+contains(one(set(of( tasks(to(perform(when(the(condi5on(is(true(and(a(different( set(of(tasks(to(perform(when(the(condi5on(is(false( ! False+path:(the(tasks(to(perform(when(the(condi5on(is( false( Lee#302#Ch.4+ 3+ ! .

4+ 4+ ! .The(Selec5on(Structure( ! Pseudocode(uses:( •  if…then…end)if)to(denote(a(selec5on(structure( •  else(to(denote(the(op5onal(false(path( •  Indent(instruc5ons(within(the(selec5on(structure( Lee#302#Ch.

Figure(4I1(SingleI(and(DualIAlterna5ve( Selec5on(Structure( Lee#302#Ch.4+ 5+ ! .

4+ 6+ ! .Figures(4I2(&(4I3(Problem(Specifica5on(and( Interface( Lee#302#Ch.

Figure(4I4(Pseudocode(Containing(Sequence( Structure( Lee#302#Ch.4+ 7+ ! .

4+ 8+ ! .Figure(4I5(Pseudocode(Containing(SingleI Alterna5ve(Selec5on(Structure( Lee#302#Ch.

Figure(4I6(Flowchart(Showing(SingleI Alterna5ve(Selec5on(Structure( Lee#302#Ch.4+ 9+ ! .

4+ 10+ ! .Figure(4I7(Pseudocode(Containing(DualI Alterna5ve(Selec5on(Structure( Lee#302#Ch.

4+ 11+ ! .Figure(4I8(Flowchart(Showing(DualIAlterna5ve( Selec5on(Structure( Lee#302#Ch.

(arithme5c(operators.(methods.(proper5es.(only(used(for(the( dual+alterna#ve0selec5on(structure( •  Condi5on(must(be(a(Boolean(expression(that(evaluates(to(either( True(or(False:(Can(contain(variables.(named( constants.(literal(constants.4+ 12+ ! .Coding(SingleIAlterna5ve(and(DualIAlterna5ve( Selec5on(Structures( ! If…Then…[Else…]EndIf+statement:( •  Used(to(code(singleI(and(dualIalterna5ve(selec5on(structures+ •  Else+clause:(An(op#onal(part(of(the(If(statement.(comparison( operators(and(logical(operators( ! Statement+block:(Set(of(statements(in(the(true(path(or(the( false(path( Lee#302#Ch.

Figure(4I9(Use(If…Then…Else(Statement( Lee#302#Ch.4+ 13+ ! .

Figure(4I9(Use(If…Then…Else(Statement( Lee#302#Ch.4+ 14+ ! .

4+ 15+ ! .Comparison(Operators( ! Comparison+operators+(or(rela0onal+operators):( •  Used(as(part(of(the(condi5on(in(an(If…Then…Else(statement(to( compare(two(values( ! Most(commonly(used(comparison(operators:( •  Equal(to:((= •  Greater(than:((> •  Greater(than(or(equal(to:((>= •  Less(than:((< •  Less(than(or(equal(to:((<= •  Not(equal(to:((<> Lee#302#Ch.

4+ 16+ ! .Figure(4I10(Using(Comparison(Operators(( Lee#302#Ch.

Figure(4I10(Using(Comparison(Operators(

Lee#302#Ch.4+

17+

!

Comparison(Operators(
! Comparison(operators:(
•  Have(no(order(of(precedence(
•  Are(evaluated(from(led(to(right(in(an(expression(
•  Are(evaluated(ader(any(arithme5c(operators(in(the(expression(

! All(expressions(containing(comparison(operators(evaluate(
to(True(or(False(only(

Lee#302#Ch.4+

18+

!

Figure(4I11(Evalua5on(Steps(for(Arithme5c(and(
Comparison(Operators(

Lee#302#Ch.4+

19+

!

Figure(4I12(Sample(Run(of(Comparing(Numeric( Values( ! Auc5on(House(applica5on(displays(lowest(and(highest(of( two(bids(entered(by(the(user( Lee#302#Ch.4+ 20+ ! .

Figure(4I13(Pseudocode(Containing(SingleI Alterna5ve(Selec5on(Structure( Lee#302#Ch.4+ 21+ ! .

4+ 22+ ! .Figure(4I14(Flowchart(Containing(SingleI Alterna5ve(Selec5on(Structure( Lee#302#Ch.

4+ 23+ ! .Figure(4I15(Code(for(SingleIAlterna5ve( Selec5on(Structure( Lee#302#Ch.

4+ 24+ ! .Figure(4I16(Illustra5on(of(Swapping(Concept( Lee#302#Ch.

4+ 25+ ! .BlockILevel(Variables(and(Block(Scope( ! Block#level+variables( •  Declared(within(a(statement(block(and(remain(in(memory(un5l(the( procedure(ends((life5me:(procedure)( ! Block+scope( •  A(blockIscope(variable(can(only(be(used(within(the(statement(block( in(which(it(was(declared( Lee#302#Ch.

NewLine(constant( •  Advances(the(inser5on(point(to(the(next(line( Lee#302#Ch.Concatena5on(Operator(and(NewLine( Constant( ! Concatena0on+operator+(&)( •  Connects(or(links(two(strings(together( •  Must(include(a(space(before(and(ader(the(ampersand( ! ControlChars.4+ 26+ ! .

Figure(4I17(Concatena5ng(Strings( Lee#302#Ch.4+ 27+ ! .

Comparing(Strings( ! Comparison/rela5onal(operators(can(be(used(to(compare( strings(and(string(literals( Lee#302#Ch.4+ 28+ ! .

Comparing(Strings( ! How(are(strings(compared?( •  Characters(are(stored(as(numeric(values((through(a(codebook)( •  Visual(Basic(uses(Unicode( •  Lehers((A.B.C)(are(arranged(alphabe5cally( •  The(numeric(value(of(A(is(less(than(the(numeric(value(of(B+ •  Characters(of(each(string(are(compared(one(by(one(un5l(a( difference(is(found( ( Lee#302#Ch.4+ 29+ ! .

4+ 30+ ! .Unicode(Mapping(( Lee#302#Ch.

Comparing(Strings( ! “Mary”(is(greater(than(“Mark”(because("y"(has(a(Unicode( value(greater(than("k"( Lee#302#Ch.4+ 31+ ! .

Empty(represents(an(empty( string.(which(is(a(string(that(contains(no(characters( •  Useful(for(determining(whether(the(user(has(provided(input(for(a( required(field(before(performing(opera5ons(on(that(field( Lee#302#Ch.4+ 32+ ! .Comparing(with(Empty(String( ! Tes5ng(for(No(Input( •  The(predefined(constant(String.

ToUpper()(and(ToLower()(Methods( ! String(comparisons(in(Visual(Basic(are(caseIsensi5ve( ! ToUpper()+method:(converts(a(string(to(uppercase( ! ToLower()+method:(converts(a(string(to(lowercase( Dim strWord1 As String = "HELLO" Dim strWord2 As String = "hello" If strWord1 = strWord2 If strWord1. equal 33+ ! . not equal ' True.ToLower() = strWord2.ToLower() Lee#302#Ch.4+ ' False.

22(ToUpper()(and(ToLower()( Methods( Lee#302#Ch.Figure(4.4+ 34+ ! .

Figure(4.4+ 35+ ! .22(ToUpper()(and(ToLower()( Methods( Lee#302#Ch.

22(ToUpper()(and(ToLower()( Methods( Lee#302#Ch.4+ 36+ ! .Figure(4.

IsNumeric()(Method( ! The(IsNumeric()(Method( •  This(method(accepts(a(string(as(an(argument(and(returns(True(if( the(string(contains(a(number( Lee#302#Ch.4+ 37+ ! .

(returns( the(number(of(characters(in(a(string( •  In(the(following(example.Length(Property( ! Determining(the(length(of(a(string( •  The(Length(property.4+ 38+ ! .(the(intNumChars(variable(contains( the(value(6:( ( •  You(can(also(determine(the(length(of(a(control’s(Text(property:( Lee#302#Ch.(a(member(of(the(String(class.String.

Figure(10I1(Determining(the(Number(of( Characters(in(a(String( Lee#302#Ch.4+ 39+ ! .

String.Text Lee#302#Ch.Text = " Hello" = strGreeting.Text = "Hello" 40+ ! .Trim()(Methods( ! Trimming(spaces(from(strings( •  There(are(three(methods(that(remove(spaces(from(strings:( ( (TrimStart() (:(removes(leading(spaces( ( (TrimEnd() ( (:(removes(trailing(spaces( Trim() ( ( (:(removes(leading(and(trailing(spaces( ! Here(is(the(general(format(for(each(method:( strGreeting = ” lblMessage1.4+ Hello " = strGreeting.TrimStart() 'lblMessage1.TrimEnd() 'lblMessage2.Text = "Hello " = strGreeting.Text lblMessage2.Text lblMessage3.Trim() 'lblMessage3.

4+ 41+ ! .Figure(10I2(Removing(Characters(from(a(String( Lee#302#Ch.

Contains()(method:(( •  Determines(if(a(string(contains(a(specific(sequence(of(characters( •  Returns(a(Boolean(value(of(True(when(the(substring(is( contained(in(the(string.4+ 42+ ! .Searching(within(a(String( ! String.(and(False(if(not( •  Performs(a(caseIsensi5ve(search( ! Argument:( •  subString:(represents(the(sequence(of(characters(to(be( searched(for( Lee#302#Ch.

IndexOf()+method:(returns(an(integer( represen5ng(the(loca5on(of(a(substring(within(a(string(( •  Return(-1(if(substring(not(found( •  The(index(of(the(first(character(in(a(string(is(0(!!!( •  Performs(a(caseIsensi5ve(search( ! Arguments:( •  subString:(sequence(of(characters(to(be(searched(for( •  startIndex:(the(star5ng(posi5on(for(the(search((zeroIrela5ve)( Lee#302#Ch.Searching(within(a(String ! String.4+ 43+ ! .

Figure(10.4+ 44+ ! .4(Searching(a(String( Lee#302#Ch.

4+ 45+ ! .4(Searching(a(String( Lee#302#Ch.Figure(10.

Accessing(the(Characters(in(a(String( ! String.Substring()+method:(accesses(any(number( of(characters(contained(in(a(string( ! Arguments:( •  startIndex:(index(of(the(first(character(to(be(accessed((zeroI rela5ve)( •  numCharsToAccess:(number(of(characters(to(be(accessed( Lee#302#Ch.4+ 46+ ! .

Figure(10I5(Accessing(Characters(in(a(String( Lee#302#Ch.4+ 47+ ! .

Figure(4I24(Comparing(Boolean(Values( ! Check+boxes:(used(to(offer(the(user(one(or(more( independent(and(nonexclusive(items(from(which(to(choose( Lee#302#Ch.4+ 48+ ! .

Figure(4I25(Code(for(Comparing(Boolean( Values( Lee#302#Ch.4+ 49+ ! .

4+ 50+ ! .Figure(4I25(Code(for(Comparing(Boolean( Values( Lee#302#Ch.

Figure(4I26(Using(Logical(Operators(in(a( Condi5on( ! Logical+(or(Boolean)(operators:(Used(to(combine(two(or( more(condi5ons(into(one(compound(condi5on( ! Compound+condi0on:(a(combina5on(of(condi5ons(using( logical(operator(s)( Lee#302#Ch.4+ 51+ ! .

Figure(4I26(Using(Logical(Operators(in(a( Condi5on( Lee#302#Ch.4+ 52+ ! .

4+ 53+ ! .Figure(4I26(Using(Logical(Operators(in(a( Condi5on( Lee#302#Ch.

Logical(Operators( ! Short#circuit+evalua0on:(an(evalua5on(in(which(the( second(condi5on(may(not(be(evaluated( ! AndAlso(evaluates(to(True(only(when(both(subI condi5ons(are(True( ! OrElse(evaluates(to(False(only(when(both(subI condi5ons(are(False( ! AndAlso((OrElse)(opera5ons(do(not(evaluate(the( second(condi5on(if(the(first(condi5on(is(False((True)( Lee#302#Ch.4+ ( 54+ ! .

4+ 55+ ! .Figure(4I27(Truth(Table(for(Logical(Operators( Lee#302#Ch.

4+ 56+ ! .Figures(4I29(&(4I30(Data(Valida5on( ! Data+valida0on:(( •  Process(of(verifying(that(the(input(data(is(within(the(expected( range( Lee#302#Ch.

Figure(4I28(Data(Valida5on(Using(AndAlso Lee#302#Ch.4+ 57+ ! .

4+ 58+ ! .Figure(4I28(Data(Valida5on(Using(OrElse Lee#302#Ch.

(Concatena5on.4+ 59+ ! .Figure(4I31(List(of(Arithme5c.( Comparison(and(Logical(Operators( Lee#302#Ch.

( Comparison(and(Logical(Operators( Lee#302#Ch.Figure(4I31(Using(Arithme5c.4+ 60+ ! .(Concatena5on.

Genera5ng(Random(Integers( ! Pseudo#random+number+generator:(a(device(that( produces(a(sequence(of(numbers(that(meets(certain( sta5s5cal(requirements(for(randomness( ! Random(class:(represents(a(pseudoIrandom(number( generator( ! Random.Next()+method:(( •  Generates(a(random(integer( •  Can(specify(minimum((inclusive)(and(maximum((exclusive)(value( Lee#302#Ch.4+ 61+ ! .

Figure(4I32(Genera5ng(Random(Integers( Lee#302#Ch.4+ 62+ ! .

Figures(4I33(&(4I34(Genera5ng(Random(
Integers(

Lee#302#Ch.4+

63+

!

BMGT302(Designing(Business(Applica5ons(
Lecture(06(
Chapter(5(–(More(on(Selec5on(Structure(

!

DR. ADAM LEE
adamlee@rhsmith.umd.edu

!

Objec5ves(
! Include(a(nested(selec5on(structure(in(pseudocode(and(in(
a(flowchart(
! Code(a(nested(selec5on(structure(
! Include(a(mul5pleIalterna5ve(selec5on(structure(in(
pseudocode(and(in(a(flowchart(
! Code(a(mul5pleIalterna5ve(selec5on(structure((
! Include(radio(buJons(in(an(interface(
! Display(a(message(in(a(message(box(
! Prevent(the(entry(of(invalid(characters(in(a(text(box(
Lee#302#Ch.5+

1+

!

5+ 2+ ! .Figure(5I1(Pseudocode(Containing(Nested( Selec5on(Structure( ! Nested+selec3on+structure:(When(a(selec5on(structure’s( true(or(false(path(contains(another(selec5on(structure.( Lee#302#Ch.

5+ 3+ ! .Figures(5I2(&(5I3(Voter(Eligibility(Applica5on( Lee#302#Ch.

Figure(5I4(Flowchart(Showing(Nested(Selec5on( Structure(in(the(True(Path( Lee#302#Ch.5+ 4+ ! .

5+ 5+ ! .Figure(5I5(Flowchart(Showing(Nested(Selec5on( Structure(in(the(False(Path( Lee#302#Ch.

5+ 6+ ! .Figure(5I6(Code(for(Figure(5I4(Flowchart( Lee#302#Ch.

Figure(5I6(Code(for(Figure(5I5(Flowchart( Lee#302#Ch.5+ 7+ ! .

5+ 8+ ! .( Lee#302#Ch.Figures(5I7(&(5I8(Yardley(Theater(Applica5on( ! Mul3ple#alterna3ve+selec3on+structures:(select(structures( that(can(choose(from(several(alterna5ves.

Figure(5I9(Pseudocode(Containing(Mul5pleI Alterna5ve(Selec5on(Structure( Lee#302#Ch.5+ 9+ ! .

5+ 10+ ! .Figure(5I10(Flowchart(Showing(Mul5pleI Alterna5ve(Selec5on(Structure( Lee#302#Ch.

Figure(5I11(Code(for(Nested(Selec5on( Structure( Lee#302#Ch.5+ 11+ ! .

Figure(5I11(Code(for(Mul5pleIAlterna5ve( Selec5on(Structure( Lee#302#Ch.5+ 12+ ! .

(which(specifies(the(value(to(be( matched( •  Ends(with(End(Select •  Has(one(Case(clause(for(each(possible(path( •  Case(Else(is(op5onal(but(must(be(the(last(clause(in(the( statement( Lee#302#Ch.The(Select(Case(Statement( ! Select+Case+statement:(( •  Used(when(there(are(many(paths(from(which(to(choose( •  Simpler(and(clearer(than(using(several(If…Then…Else( statements( •  Begins(with(Select(Case.5+ 13+ ! .

Figure(5I12(Using(Select(Case(Statement(( Lee#302#Ch.5+ 14+ ! .

(the(Case(Else( clause(is(processed( Lee#302#Ch.5+ 15+ ! .(separated(by( commas( •  Only(one(value(must(be(matched(to(process(the(code(in(this(Case( clause( ! Processing(of(a(Case(clause(code(stops(when(the(next( Case(clause(is(encountered( ! If(no(values(in(Case(clauses(are(matched.The(Select(Case(Statement( ! Case(clause(may(have(more(than(one(value.

5+ 16+ ! .Specifying(a(Range(of(Values(in(a(Case(Clause( ! To(and(Is(keywords:(used(to(specify(a(range(of(values(in(a( Case(clause’s(expression(list( ! To:(( •  When(you(know(both(lower(and(upper(bounds(of(the(range( ! Is:(( •  When(you(know(only(one(end(of(the(range( •  Used(with(a(comparison+operator+ Lee#302#Ch.

Figure(5I13(Specifying(a(Range(in(Case(Clause( Lee#302#Ch.5+ 17+ ! .

(Panel.5+ 18+ ! .Using(Radio(BuJons(in(an(Interface( ! Radio+buEon+control:(allows(the(user(to(select(only(one(of( a(group(of(two(or(more(choices( ! Radio(buJon(choices(are(related(but(mutually(exclusive.(and(TableLayout(controls( Lee#302#Ch.( only(one(can(be(selected( ! Container+control:( •  Isolates(a(group(of(radio(buJons( •  Includes(GroupBox.

5+ 19+ ! .Using(Radio(BuJons(in(an(Interface( ! Minimum(number(of(radio(buJons(in(a(group(is(two( •  Must(select(a(radio(buJon(to(deselect(another( ! Recommended(maximum(number(in(a(group:(seven( ! Windows(standard(is(to(set(one(as(the(default(radio(buJon( •  Shows(as(selected(when(the(form(appears( •  The(most(likely(selec5on(or(the(first(radio(buJon(in(the(group( ! Set(the(Checked(property(to(True(to(make(it(the(default( radio(buJon( Lee#302#Ch.

Figure(5I14(Using(Radio(BuJons(in(an(Interface( Lee#302#Ch.5+ 20+ ! .

5+ 21+ ! .Figure(5I15(If…Then…Else(Statement( Lee#302#Ch.

Figure(5I15(Select(Case(Statement( Lee#302#Ch.5+ 22+ ! .

Show()(Method( ! MessageBox.5+ 23+ ! .(one(or(more(buJons.MessageBox.Show()+method:( •  Displays(a(message(box(with(text.(and(an( icon( ! When(a(message(box(is(displayed.Show(()(returns(an(integer(value(indica5ng( which(buJon(the(user(selected( Lee#302#Ch.(the(program(waits(un5l( the(user(selects(a(buJon( ! MessageBox.

Show()( Method( Lee#302#Ch.Figure(5I16(Using(MessageBox.5+ 24+ ! .

5+ 25+ ! .Show()( Method( Lee#302#Ch.Figure(5I16(Using(MessageBox.

5+ 26+ ! .Message(Boxes(Displayed(by(Code(in(Figure( 5I16( ! Example(1( ! Example(2( Lee#302#Ch.

5+ 27+ ! .Figure(5I19(Using(Return(Value( Lee#302#Ch.

Back(constant(to(represent(the( backspace(key(on(the(keyboard( Lee#302#Ch.Using(the(KeyPress(Event( ! Can(prevent(a(text(box(from(accep5ng(an(inappropriate( character(by(coding(the(text(box’s(KeyPress(event( ! KeyPress+event:(occurs(each(5me(the(user(presses(a(key( while(the(control(has(the(focus( •  Use(e(parameter’s(KeyChar(property(to(determine(pressed(key( •  Use(e(parameter’s(Handled(property(to(cancel(the(key(if(it(is( inappropriate.5+ 28+ ! .(set(it(to(True(to(discard(the(character( ! Use(ControlChars.

5+ 29+ ! .Using(the(KeyPress(Event( Lee#302#Ch.

5+ 30+ ! .Figure(5I20(Using(KeyPress(Event(to(Cancel( Invalid(Characters( Lee#302#Ch.

Sign up to vote on this title
UsefulNot useful