1 / 85

CHAPTER FIVE

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

ernie
Download Presentation

CHAPTER FIVE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CHAPTER FIVE Mobile Applications Using Decision Structures

  2. 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

  3. 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

  4. 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

  5. Chapter Project Chapter 5: Mobile Applications Using Decision Structures

  6. 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

  7. 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

  8. Create a Smart Device Application Chapter 5: Mobile Applications Using Decision Structures

  9. 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

  10. Placing Objects on the PocketPC Form Object Chapter 5: Mobile Applications Using Decision Structures

  11. 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

  12. Using the Panel Object Chapter 5: Mobile Applications Using Decision Structures

  13. 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

  14. 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

  15. Adding the RadioButton Objects Chapter 5: Mobile Applications Using Decision Structures

  16. 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

  17. 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

  18. GroupBox versus Panel Chapter 5: Mobile Applications Using Decision Structures

  19. 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

  20. MsgBox [ Message only ] • MsgBox( “Message” ) • -------------------------------------------------------------- • MsgBox(“Enter the Linear Feet of the Cabinet”) Chapter 5: Mobile Applications Using Decision Structures

  21. Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures

  22. 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

  23. Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures

  24. 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

  25. Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures

  26. MsgBoxStyle Button(s) Enumeration Chapter 5: Mobile Applications Using Decision Structures

  27. 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

  28. Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures

  29. MsgBoxStyle Icon Enumeration Chapter 5: Mobile Applications Using Decision Structures

  30. 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

  31. 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

  32. Values Returned by a MessageBox[ returns a value of type DialogResult ] Chapter 5: Mobile Applications Using Decision Structures

  33. Displaying a Message Box[ 1 Argument ] [ The Show method takes up to 4 arguments ] Chapter 5: Mobile Applications Using Decision Structures

  34. Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures

  35. Displaying a Message Box[ 2 Arguments ] Chapter 5: Mobile Applications Using Decision Structures

  36. Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures

  37. Displaying a Message Box[ 3 Arguments ] Chapter 5: Mobile Applications Using Decision Structures

  38. Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures

  39. MessageBoxButtons Enumeration Chapter 5: Mobile Applications Using Decision Structures

  40. Displaying a Message Box[ 4 Arguments ] Chapter 5: Mobile Applications Using Decision Structures

  41. Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures

  42. MessageBoxIcon Enumeration There is also the member name None for which no icon is displayed Chapter 5: Mobile Applications Using Decision Structures

  43. 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

  44. 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

  45. Displaying a Message Box Chapter 5: Mobile Applications Using Decision Structures

  46. Displaying a Message Box[ 2 arguments ] Chapter 5: Mobile Applications Using Decision Structures

  47. 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

  48. 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

  49. Relational Operators[ used to create expressions (conditions) ] Chapter 5: Mobile Applications Using Decision Structures

  50. 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

More Related