860 likes | 1.12k Views
CHAPTER FIVE. Mobile Applications Using Decision Structures. Objectives. Write programs for devices other than a personal computer Understand the use of handheld technology ( aka smart devices ) Write handheld applications for a Personal Digital Assistant Use the Panel object
E N D
CHAPTER FIVE Mobile Applications Using Decision Structures
Objectives • Write programs for devices other than a personal computer • Understand the use of handheld technology ( aka smart devices ) • Write handheld applications for a Personal Digital Assistant • Use the Panel object • Place RadioButton objects in applications Chapter 5: Mobile Applications Using Decision Structures
Objectives • Display a message box • Make decisions using If…Then statements • Make decisions using If…Then…Else statements • Make decisions using nested If statements Chapter 5: Mobile Applications Using Decision Structures
Objectives • Make decisions using logical operators • Make decisions using Case statements • Insert code snippets • Test input to ensure a value is numeric Chapter 5: Mobile Applications Using Decision Structures
Chapter Project Chapter 5: Mobile Applications Using Decision Structures
Pervasive Devices • Visual Studio has a built-in emulatorthat displays a “working” Pocket PC • Pervasive devices have become important in many business venues Chapter 5: Mobile Applications Using Decision Structures
Create a Smart Device Application • New Project • if necessary, click the plus sign next to Smart Device in the Project types pane on the left side of the New Project dialog box • Click Pocket PC 2003 under Smart Device in the Project types list. [Windows Mobile 6] • In the Templates pane, click Device Application • Change the Name of the Smart Device application from DeviceApplication1 to WoodCabinetEstimate. Click the OK button Chapter 5: Mobile Applications Using Decision Structures
Create a Smart Device Application Chapter 5: Mobile Applications Using Decision Structures
Placing Objects on the Pocket PC Form Object • Many of the same objects used in a Windows application can be placed on the PocketPC Form object • You cannot resize the Form object • The PocketPC Form object can be named in the same manner as a Windows Form object using the (Name) property in the Properties window • Change the Text property of the PocketPC Form object from Form1 to Estimate in the same manner used for the Windows Form object Chapter 5: Mobile Applications Using Decision Structures
Placing Objects on the PocketPC Form Object Chapter 5: Mobile Applications Using Decision Structures
Using the Panel Object • If necessary, open the Device Containers category of the Toolbox by clicking the plus sign next to the category name. • A Panel is used as a container for other controls. In this application it will be used to group radio buttons. • (Name) property --- > pnlWoodType Chapter 5: Mobile Applications Using Decision Structures
Using the Panel Object Chapter 5: Mobile Applications Using Decision Structures
Adding the 3 RadioButton Objects • Drag and drop one RadioButton object from the Toolbox onto the PocketPC Form object inside the Panel object. • Drag a second RadioButton object from the Toolbox onto the PocketPC Form object using blue snap lines to align and separate the RadioButton objects vertically • add a third RadioButton object Chapter 5: Mobile Applications Using Decision Structures
Adding the RadioButton Objects • Name the RadioButton objects (Name) property • The names for the radio buttons, from top to bottom, should be: • radPine • radOak • radCherry • Change the Text property for each RadioButton • Pine • Oak • Cherry Chapter 5: Mobile Applications Using Decision Structures
Adding the RadioButton Objects Chapter 5: Mobile Applications Using Decision Structures
Windows Application Container Objects • For Windows applications, Visual Basic provides 5 additional container classes in addition to the Panel class. • FlowLayoutPanel • GroupBox • SplitContainer • TabControl • TableLayoutPanel • GroupBox is most popular Chapter 5: Mobile Applications Using Decision Structures
Windows Application Container Objects GroupBox controls are typically used to group radio buttons, but they are NOT available for smart devices so for a smart device use a Panel control Chapter 5: Mobile Applications Using Decision Structures
GroupBox versus Panel Chapter 5: Mobile Applications Using Decision Structures
Examples using MsgBox Function • The following examples demonstrate displaying a message box using the VB 6 style MsgBox Function. • Later examples will show using the .NET show method of the MessageBox class Chapter 5: Mobile Applications Using Decision Structures
MsgBox [ Message only ] • MsgBox( “Message” ) • -------------------------------------------------------------- • MsgBox(“Enter the Linear Feet of the Cabinet”) Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures
MsgBox [ with Caption ] • MsgBox( “Message”, ,”Caption” ) • ------------------------------------------------------------------ • MsgBox(“Enter the Linear Feet of the Cabinet” _ , , _ “Error Missing a Number”) • Note the , , to indicate an optional positional parameter has been skipped ( will use default value ) Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures
MsgBox [ with Caption and Button ] • MsgBox( “Message”, <Button Entry> , ”Caption” ) • ---------------------------------------------------------------------- • MsgBox(“User name is missing”, _ MsgBoxStyle.OKCancel, _ “Entry Error”) • MsgBox(“You have been disconnected”, _MsgBoxStyle.RetryCancel, _ “ISP”) • MsgBox(“You have been disconnected”, _5, _ “ISP”) Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures
MsgBoxStyle Button(s) Enumeration Chapter 5: Mobile Applications Using Decision Structures
MsgBox [ with Caption, Button, and Icon ] • MsgBox( “Message”, <Button Entry or Icon Picture> , ”Caption” ) • ----------------------------------------------------------------------------------------- • MsgBox(“User name is missing”, _ MsgBoxStyle.OKCancel or MsgBoxStyle.Critical, _ ‘or / + “User Name Error”) • MsgBox(“User name is missing”, _ 1 or 16, _ ‘also 1 + 16 or 17 “User Name Error”) • MsgBox(“You have been disconnected”, _MsgBoxStyle.RetryCancel + MsgBoxStyle.Question, _ ‘+ / or “ISP”) • MsgBox(“You have been disconnected”, _5 + 32, _ ‘also 5 + 32 or 37 “ISP”) Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures
MsgBoxStyle Icon Enumeration Chapter 5: Mobile Applications Using Decision Structures
MessageBox Class Examples • The following examples use the show method of the MessageBox class. • The benefit of using this is it would available for use in C# applications as well. • This is the newer [ preferred ] method • Oddly enough, this is what was used in the previous version of the book… Chapter 5: Mobile Applications Using Decision Structures
MessageBox Class Syntax • 1 – 4 Arguments ( overloaded ) [common usage] • Message to be displayed • Caption to display in the title bar [ blank if omitted ] • MessageBoxButtons to be displayed [ OK if omitted ] • MessageBoxIcon to be displayed [ blank if omitted ] or • MessageBoxImage to be displayed [ blank if omitted ] .NET Framework V 3.0 • The Show method returns a value of type DialogResult Chapter 5: Mobile Applications Using Decision Structures
Values Returned by a MessageBox[ returns a value of type DialogResult ] Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box[ 1 Argument ] [ The Show method takes up to 4 arguments ] Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box[ 2 Arguments ] Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box[ 3 Arguments ] Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures
MessageBoxButtons Enumeration Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box[ 4 Arguments ] Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures
MessageBoxIcon Enumeration There is also the member name None for which no icon is displayed Chapter 5: Mobile Applications Using Decision Structures
Message Box IntelliSense • In the code editing window, inside the event handler you are coding, press CTRL+SPACEBAR. IntelliSense displays the allowable entries. • Type mes to select MessageBox in the IntelliSense list • Type a period ( . ) to insert the dot operator. IntelliSense displays a list of the allowable entries. Type s to select Show in the IntelliSense list • Type the following text: (“You have been disconnected from the Internet”, “ISP”, Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box • Here are the last two arguments for the Show method: • MessageBoxButtons.RetryCancel • MessageBoxIcon.Warning MessageBox.Show (“You have been disconnected from the Internet”,_ “ISP”,_ MessageBoxButtons.RetryCancel,_ MessageBoxIcon.Warning) • Type a right parenthesis and then press the ENTER key Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures
Displaying a Message Box[ 2 arguments ] Chapter 5: Mobile Applications Using Decision Structures
Making Decisions with Conditional Statements Using an If…Then Statement • A decision structure is one of the three fundamental control structures used in computer programming. Sequence, Selection, Repetition • When a condition is tested in a Visual Basic program, the condition either is true or false Chapter 5: Mobile Applications Using Decision Structures
If..Then..Else Statement If...Then...Else Statement Conditionally executes a group of statements, depending on the value of an expression. Ifcondition [ Then ] [ statements ] [ ElseIf elseifcondition [ Then ] [ elseifstatements ] ] [ Else [ elsestatements ] ] End If -or- If condition Then [ statements ] [ Else elsestatements ] Anything in brackets ( [ ] ) is optional Chapter 5: Mobile Applications Using Decision Structures
Relational Operators[ used to create expressions (conditions) ] Chapter 5: Mobile Applications Using Decision Structures
Comparing Strings • A string value comparison compares each character in two strings, starting with the first character in each string ( using ordinal values in the Unicode Character Set ) If the strings are not the same size, the shorter string is padded on the right with spaces to make it the same length. Note: spaces come earlier in the collating sequence than do letters and numbers. Chapter 5: Mobile Applications Using Decision Structures