Chapter 03

3,332 views

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,332
On SlideShare
0
From Embeds
0
Number of Embeds
206
Actions
Shares
0
Downloads
82
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Chapter 03

  1. 1. CHAPTER THREE<br />Program Design and Coding<br />
  2. 2. Chapter 3: Program Design and Coding<br />2<br />Objectives<br />Change the BackColor property of an object<br />Add images to a PictureBox object<br />Locate and save an image from the World Wide Web<br />Import an image into the Program Resources folder<br />Size an image<br />
  3. 3. Chapter 3: Program Design and Coding<br />3<br />Objectives<br />Set the Visible property in the Properties window<br />Set the Enabled property in the Properties window<br />Run a Visual Basic 2010 program<br />Enter Visual Basic 2010 code<br />Understand Visual Basic 2010 code statement formats<br />
  4. 4. Chapter 3: Program Design and Coding<br />4<br />Objectives<br />Use IntelliSense to enter Visual Basic 2010 code statements<br />Using code, set the Visible property of an object<br />Using code, set the Enabled property of an object<br />Enter comments in Visual Basic 2010 code<br />
  5. 5. Chapter 3: Program Design and Coding<br />5<br />Objectives<br />Correct errors in Visual Basic 2010 code<br />Write code to use the Close() procedure<br />Print code<br />Prepare an Event Planning Document<br />
  6. 6. Chapter 3: Program Design and Coding<br />6<br />BackColor Property<br />Click the Windows Form object to select it<br />If necessary, scroll in the Properties window until the BackColor property is displayed, and then click the right column of the BackColor property<br />Click the BackColor arrow. Then, if necessary, click the Web tab to display the Web tabbed page<br />Scroll to display the color you wish to apply<br />Click the color you wish to apply on the color list<br />
  7. 7. Chapter 3: Program Design and Coding<br />7<br />BackColor Property<br />
  8. 8. Chapter 3: Program Design and Coding<br />8<br />Locating and Saving an Image from the World Wide Web<br />Open your Internet browser. Then, enter scsite.com/vb2010/ch3/imagesin the Address box and press the ENTER key<br />Locate the StandardRoom.jpg image and then right-click the image<br />Click Save Picture As on the shortcut menu<br />Identify the drive and folder where the image will be stored. Enter the image file name, StandardRoom, in the File name text box<br />Click the Save button in the Save Picture dialog box to save the image in the selected location<br />
  9. 9. Chapter 3: Program Design and Coding<br />9<br />Locating and Saving an Image from the World Wide Web<br />
  10. 10. Chapter 3: Program Design and Coding<br />10<br />Importing the Image into the Program Resources Folder<br />With Visual Studio 2010 and the Hotel Room Selection Visual Basic program open, select the picStandardRoomPictureBox object by clicking it. Scroll in the PictureBox Properties window until the Image property is visible. Click the Image property name in the left list in the Properties window<br />Click the Ellipsis button in the right column of the Image property<br />Click the Import button in the Select Resource dialog box. Then, using the features of the Open dialog box, locate the file you want to import into the program<br />
  11. 11. Chapter 3: Program Design and Coding<br />11<br />Importing the Image into the Program Resources Folder<br />Click the Open button in the Open dialog box<br />With the StandardRoom file name selected in the Project resource file list, click the OK button in the Select Resource dialog box<br />
  12. 12. Chapter 3: Program Design and Coding<br />12<br />Sizing an Image<br />With the PictureBox object containing the StandardRoom image selected, scroll in the picStandardRoom Properties window until you see the SizeMode property. Click the SizeMode property name in the left column and then click the SizeMode arrow in the right column of the SizeMode property<br />Click StretchImage in the SizeMode list<br />
  13. 13. Chapter 3: Program Design and Coding<br />13<br />Sizing an Image<br />
  14. 14. Chapter 3: Program Design and Coding<br />14<br />Visible Property<br />If necessary, select the picStandardRoom PictureBox object. Scroll in the Properties window until the Visible property is displayed. Click the Visible property name in the left column, and then click the Visible arrow in the right column of the Visible property<br />Click False on the Visible property list<br />
  15. 15. Chapter 3: Program Design and Coding<br />15<br />Visible Property<br />
  16. 16. Chapter 3: Program Design and Coding<br />16<br />Enabled Property<br />Select the btnSelectRoom object. Scroll in the Properties window until the Enabled property is displayed. Click the Enabled property name in the left column, and then click the Enabled arrow in the right column of the Enabled property<br />Click False on the Enabled property list<br />
  17. 17. Chapter 3: Program Design and Coding<br />17<br />Enabled Property<br />
  18. 18. Chapter 3: Program Design and Coding<br />18<br />Running a Program<br />Point to the Start Debugging button on the Standard toolbar<br />Click the Start Debugging button on the Standard toolbar<br />
  19. 19. Chapter 3: Program Design and Coding<br />19<br />Entering Visual Basic Code for Event Handling<br />With Visual Studio 2010 and the Hotel Room Selection program open and the frmHotelRoomSelection.vb [Design] tabbed window visible, point to the Standard Room Button object in the Windows Form object<br />Double-click the Standard Room Button object<br />
  20. 20. Chapter 3: Program Design and Coding<br />20<br />Entering Visual Basic Code for Event Handling<br />
  21. 21. Chapter 3: Program Design and Coding<br />21<br />Visual Basic 2010 Coding Statements<br />The Visual Basic syntax specifies how each statement must be written<br />When the user clicks the Standard Room button while the program is running, the standard room image should be displayed in the picStandardRoom PictureBox object<br />
  22. 22. Chapter 3: Program Design and Coding<br />22<br />General Format of a Visual Basic Statement<br />
  23. 23. Chapter 3: Program Design and Coding<br />23<br />IntelliSense<br />IntelliSense displays all allowable entries you can make in a Visual Basic statement each time a dot (period), equal sign, or other special character required for the statement is typed<br />
  24. 24. Chapter 3: Program Design and Coding<br />24<br />Entering a Visual Basic Statement<br />With the code window open and the insertion point positioned as shown in Figure 3-25 on page 131, type picfollowed by a period<br />To identify the correct entry, type the first letters of the entry until the entry is selected. In this case, type son your keyboard<br />When IntelliSense highlights the correct object name, press the key on the keyboard corresponding to the entry that is to follow the object name. In this case, press the PERIOD key<br />As with the object name in the second step, the next step is to enter one or more characters until IntelliSense highlights the desired property in the list. Type the letter, v on your keyboard<br />
  25. 25. Chapter 3: Program Design and Coding<br />25<br />Entering a Visual Basic Statement<br />Press the key for the character that is to follow the property name. In this case, press the SPACEBAR on the keyboard<br />Press the EQUAL SIGN key on the keyboard and then press the SPACEBAR. On the IntelliSense list, click the Common tab to display the most common results<br />Type t on the keyboard<br />Press the key for the character that is to follow the True entry. In this case, press the ENTER key<br />
  26. 26. Chapter 3: Program Design and Coding<br />26<br />Entering a Visual Basic Statement<br />
  27. 27. Chapter 3: Program Design and Coding<br />27<br />Setting the Visible Property to False<br />With the insertion point on the second line of the code editing window for the Click event of the Standard Room button, type picon your keyboard<br />Type dto highlight the picDeluxeRoom entry in the IntelliSense list<br />Press the key on the keyboard for the character that is to follow the object name. In this case, press the PERIOD key<br />Press the SPACEBAR, press the EQUAL SIGN key, and then press the SPACEBAR<br />Type f and then press the ENTER key<br />
  28. 28. Chapter 3: Program Design and Coding<br />28<br />Setting the Visible Property to False<br />
  29. 29. Chapter 3: Program Design and Coding<br />29<br />Enabled Property<br />Type btnto display the IntelliSense list<br />Type seuntil IntelliSense highlights the btnSelectRoom entry in the list<br />Type a period, type e, press the SPACEBAR, press the EQUAL SIGN key, press the SPACEBAR again, and then type t to select True in the IntelliSense list<br />Press the ENTER key to enter the completed statement and place the insertion point on the next line<br />
  30. 30. Chapter 3: Program Design and Coding<br />30<br />Enabled Property<br />
  31. 31. Chapter 3: Program Design and Coding<br />31<br />Comments in Program Statements<br />To insert a blank line following the event code generated by Visual Studio that begins with the word, Private, click anywhere in that line and then press the END key on your keyboard<br />Press the ENTER key<br />Type the first line of the comments, beginning with an apostrophe, as shown in Figure 3-46 on page 143, and then press the ENTER key<br />
  32. 32. Chapter 3: Program Design and Coding<br />32<br />Comments in Program Statements<br />
  33. 33. Chapter 3: Program Design and Coding<br />33<br />Same Line Comments<br />
  34. 34. Chapter 3: Program Design and Coding<br />34<br />Introductory Comments<br />Click to the left of the word, Public, on line 1 in the program to place the insertion point on that line<br />Press the ENTER key one time, and then press the UP ARROW key one time<br />Type an apostrophe, a space, the text, Program Name: and then press the TAB key one time<br />Type Hotel Room Selection as the name of the program. Then, press the ENTER key<br />
  35. 35. Chapter 3: Program Design and Coding<br />35<br />Introductory Comments<br />
  36. 36. Chapter 3: Program Design and Coding<br />36<br />Correcting Errors in Code<br />Using IntelliSense reduces the likelihood of coding errors considerably, although it is still possible to code an error<br />One possible error may be forgetting an apostrophe in a comment statement<br />A build errors message means the Visual Basic compiler detected a coding error in the program<br />
  37. 37. Correcting Errors in Code<br />Chapter 3: Program Design and Coding<br />37<br />
  38. 38. Chapter 3: Program Design and Coding<br />38<br />Correcting Errors in Code<br />Click the No button in the Microsoft Visual Studio dialog box that informs you of a build error<br />Double-click anywhere on the error line<br />Click in the leftmost column on line 7 to place the insertion point at that location<br />Type an apostrophe<br />Click anywhere in the code editing window<br />
  39. 39. Chapter 3: Program Design and Coding<br />39<br />Correcting Errors in Code<br />
  40. 40. Chapter 3: Program Design and Coding<br />40<br />Additional Click Events<br />On the frmHotelRoomSelection.vb [Design] tabbed page, double-click the Exit Window Button object<br />
  41. 41. Chapter 3: Program Design and Coding<br />41<br />Close Procedure<br />With the insertion point positioned as shown in Figure 3-64 on page 154, type cloto highlight Close in the IntelliSense list<br />Press the ENTER key<br />
  42. 42. Chapter 3: Program Design and Coding<br />42<br />Printing Code<br />Click File on the menu bar to display the File menu<br />Click Print on the File menu to display the Print dialog box<br />Ensure that a check mark appears in the Include line numbers check box if you want line numbers on your printout. Most developers prefer line numbers on printouts<br />Make any other selections you find necessary in the Print dialog box<br />Click the OK button in the Print dialog box to print the code<br />
  43. 43. Chapter 3: Program Design and Coding<br />43<br />Event Planning Document<br />
  44. 44. Chapter 3: Program Design and Coding<br />44<br />Phase 4 – Code the Program<br />After the events and tasks within the vents have been identified, the developer is ready to code the program<br />Entering Visual Basic statements to accomplish the tasks specified on the event planning document<br />Developer enters the code and implements the logic<br />
  45. 45. Chapter 3: Program Design and Coding<br />45<br />Summary<br />Change the BackColor property of an object<br />Add images to a PictureBox object<br />Locate and save an image from the World Wide Web<br />Import an image into the Program Resources folder<br />Size an image<br />
  46. 46. Chapter 3: Program Design and Coding<br />46<br />Summary<br />Set the Visible property in the Properties window<br />Set the Enabled property in the Properties window<br />Run a Visual Basic 2010 program<br />Enter Visual Basic 2010 code<br />Understand Visual Basic 2010 code statement formats<br />
  47. 47. Chapter 3: Program Design and Coding<br />47<br />Summary<br />Use IntelliSense to enter Visual Basic 2010 code statements<br />Using code, set the Visible property of an object<br />Using code, set the Enabled property of an object<br />Enter comments in Visual Basic 2010 code<br />
  48. 48. Chapter 3: Program Design and Coding<br />48<br />Summary<br />Correct errors in Visual Basic 2010 code<br />Write code to use the Close() procedure<br />Print code<br />Prepare an Event Planning Document<br />
  49. 49. CHAPTER THREE COMPLETE<br />Program Design and Coding<br />

×