SlideShare uma empresa Scribd logo
1 de 45
CHAPTER EIGHT Using Procedures and Exception Handling
Chapter 8: Using Procedures and Exception Handling 2 Objectives Create a splash screen Pause the splash screen Add a ComboBox object to a Windows Form Write Code for a SelectedIndexChanged event Code a Sub procedure
Chapter 8: Using Procedures and Exception Handling 3 Objectives Pass an argument to a procedure by value Pass an argument to a procedure by reference Code a Function procedure to return a value Create a class-level variable Catch an exception using a Try-Catch block
Chapter 8: Using Procedures and Exception Handling 4 Introduction As an application grows, it is important to divide each facet of a problem into separate sections of code called procedures Try-Catch blocks can check for any error a user might commit One way to make your programs more professional is to display a splash screen while the full program loads
Chapter 8: Using Procedures and Exception Handling 5 Creating a Splash Screen Create a Windows application named Ocean Tours. Name the form frmTours. Click Project on the menu bar and then click Add New Item on the Project menu In the Add New Item dialog box, select Splash Screen in the center pane  Click the Add button in the Add New Item dialog box Click the splash screen form in the left side of the form to select the form. To set the application to display the splash screen first, right-click OceanTours in the Solution Explorer Click Properties on the shortcut menu
Chapter 8: Using Procedures and Exception Handling 6 Creating a Splash Screen In the Windows application framework properties section, click the Splash screen list arrow, and then click SplashScreen1 to select the form as the splash screen used for project Click the Assembly Information Button on the Properties Designer to open the Assembly Information dialog box To customize the splash screen, change the Title to Ocean Tours and the Copyright to the present year. The File Version can be changed as you update the application
Chapter 8: Using Procedures and Exception Handling 7 Creating a Splash Screen Click the OK button on the Assembly Information dialog box. Close the OceanTours* Project Designer window.To change the predefined image, first download the ocean.jpg picture from the scsite.com/vb2010/ch8/images Web site and store the image in a location you remember. Then, click the SplashScreen1.vb [Design] tab. Click the left side of the splash screen, making sure to select the entire splash screen form.TheProperties window should identify MainLayoutPanel if you have selected the entire splash screen form. Click to the right of the Background Image property in the Properties window, and then click the ellipsis button. In the Select Resource dialog box, click the Project resource file radio button if necessary. Import the ocean.jpg picture by clicking the Import button in the Select Resource dialog box and selecting the ocean.jpg image from the location where you stored it. Click the OK button in the Select Resource dialog box Run the application by clicking the Start Debugging button on the Standard toolbar
Chapter 8: Using Procedures and Exception Handling 8 Creating a Splash Screen
Chapter 8: Using Procedures and Exception Handling 9 Pausing the Splash Screen After the splash screen loads, the application executes any code in the form load event handler. To display the splash screen for five seconds, the code that calls the Sleep procedure should be in the form load event handler. To open the code editor window and the form load event handler, double-click the background of the frmTours Windows Form object in the Design window Click inside the frmToursLoad event handler. Type Threading. To cause IntelliSense to display a list of possible entries. If necessary, type T to select Thread from the IntelliSense list. Type .S to select Sleep from the IntelliSense list. Type (5000)
Chapter 8: Using Procedures and Exception Handling 10 Pausing the Splash Screen
Chapter 8: Using Procedures and Exception Handling 11 Adding a ComboBox Object Drag the ComboBox .NET component from the Common Controls category of the Toolbox to the approximate location where you want to place the ComboBox object With the ComboBox object selected, scroll in the Properties window to the (Name) property. Double-click in the right column of the (Name) property and then enter the name cboIsland In the Properties window, scroll to the Text property. Click to the right of the Text property and enter Select Island Location: to specify the text that appears in the combo box. Resize the ComboBox object as needed to display the data in the box
Chapter 8: Using Procedures and Exception Handling 12 Adding a ComboBox Object In the Properties window, scroll to the Items property, and click to the right of the Items property on the word (Collection). Click the ellipsis button. The String Collection Editor dialog box opens. Enter the island locations Aruba (press ENTER), Jamaica (press ENTER), and Key West In the String Collection Editor dialog box, click the OK button. Click the Start Debugging button on the Standard toolbar to run the application. Click the list arrow on the right of the ComboBox object to view the contents. You can select a choice from the list
Chapter 8: Using Procedures and Exception Handling 13 Adding a ComboBox Object
Handling SelectedIndexChanged Events Chapter 8: Using Procedures and Exception Handling 14
Chapter 8: Using Procedures and Exception Handling 15 Handling SelectedIndexChanged Events Select the ComboBox object named cboIsland on the Windows Form object Double-click the ComboBox object. Close the Toolbox
Chapter 8: Using Procedures and Exception Handling 16 Coding a Sub Procedure When a program is broken into manageable parts, each part is called a procedure A procedure is a named set of code that performs a given task A Sub procedure is a procedure that completes its task but does not return any data to the calling procedure A Sub procedure is the series of Visual Basic statements enclosed by the Sub and End Sub statements A Sub procedure is called with a statement consisting of the procedure name and a set of parentheses in the form of a procedure call
Chapter 8: Using Procedures and Exception Handling 17 Coding a Sub Procedure
Chapter 8: Using Procedures and Exception Handling 18 Coding a Sub Procedure
Chapter 8: Using Procedures and Exception Handling 19 Passing Arguments
Chapter 8: Using Procedures and Exception Handling 20 Passing Arguments by Value (ByVal) When a procedure is called, the call statement can pass an argument to the called procedure The value is copied into a variable whose name is specified in the Sub procedure declaration statement
Chapter 8: Using Procedures and Exception Handling 21 Passing Arguments by Value (ByVal)
Chapter 8: Using Procedures and Exception Handling 22 Passing Arguments by Value (ByVal)
Chapter 8: Using Procedures and Exception Handling 23 Passing Arguments by Reference The second way in which to pass an argument from a calling procedure to a called Sub procedure is by reference You specify you want to pass a value by reference by entering the keyword ByRef in the Sub procedure declaration Passing a value by reference allows code in the Sub procedure to modify the contents of the variable that is being passed because when you use ByRef, you are passing a reference to the variable that holds the value instead of the value as when you use ByVal
Chapter 8: Using Procedures and Exception Handling 24 Passing Arguments by Reference
Chapter 8: Using Procedures and Exception Handling 25 Passing Arguments by Reference
Chapter 8: Using Procedures and Exception Handling 26 Passing Multiple Arguments You can pass as many arguments as needed to a Sub procedure If you have more than one argument, the variables are passed in the same order in which they appear in the procedure call statement
Chapter 8: Using Procedures and Exception Handling 27 Function Procedures A Function procedure is similar to a Sub procedure except that a Function procedure returns a single value to the calling procedure
Chapter 8: Using Procedures and Exception Handling 28 Function Procedures The Function procedure is different in appearance from a Sub procedure in the following ways: The Function procedure call has a receiving variable that is assigned the returned value from the Function procedure The data type of the return value is listed in the procedure declaration The keyword Return is used in the Function procedure to return a single value
Chapter 8: Using Procedures and Exception Handling 29 Function Procedures
Chapter 8: Using Procedures and Exception Handling 30 Creating a Private Class-Level Variable When a class-level variable cannot be referenced outside the class in which it is declared, the variable is said to have Private access
Chapter 8: Using Procedures and Exception Handling 31 Exception Handling The Try-Catch set of statements detects exceptions and takes corrective action
Chapter 8: Using Procedures and Exception Handling 32 Exception Handling
Chapter 8: Using Procedures and Exception Handling 33 Exception Handling
Chapter 8: Using Procedures and Exception Handling 34 Exception Handling
Chapter 8: Using Procedures and Exception Handling 35 Program Design
Chapter 8: Using Procedures and Exception Handling 36 Program Design
Chapter 8: Using Procedures and Exception Handling 37 Program Design
Chapter 8: Using Procedures and Exception Handling 38 Program Design when using Sub and Function Procedures When a program becomes larger, often it is advantageous to break the program into procedures, which perform specific tasks within the program Makes the program easier to read, understand, and debug The developer must determine what code should be placed in a procedure.  Procedures should: Perform a single task Perform reasonably substantial processing Use Sub and Function procedures appropriately
Chapter 8: Using Procedures and Exception Handling 39 Event Planning Document
Chapter 8: Using Procedures and Exception Handling 40 Event Planning Document
Event Planning Document Chapter 8: Using Procedures and Exception Handling 41
Event Planning Document Chapter 8: Using Procedures and Exception Handling 42
Chapter 8: Using Procedures and Exception Handling 43 Summary Create a splash screen Pause the splash screen Add a ComboBox object to a Windows Form Write Code for a SelectedIndexChanged event Code a Sub procedure
Chapter 8: Using Procedures and Exception Handling 44 Summary Pass an argument to a procedure by value Pass an argument to a procedure by reference Code a Function procedure to return a value Create a class-level variable Catch an exception using a Try-Catch block
CHAPTER EIGHT COMPLETE Using Procedures and Exception Handling

Mais conteúdo relacionado

Mais procurados

Chapter 05 show
Chapter 05 showChapter 05 show
Chapter 05 showchda01008
 
Chapter 03 - Program Coding and Design
Chapter 03 - Program Coding and DesignChapter 03 - Program Coding and Design
Chapter 03 - Program Coding and Designpatf719
 
Cookbook Oracle SOA Business Rules
Cookbook Oracle SOA Business RulesCookbook Oracle SOA Business Rules
Cookbook Oracle SOA Business RulesEmiel Paasschens
 
Open Office Calc : Lesson 07
Open Office Calc : Lesson 07Open Office Calc : Lesson 07
Open Office Calc : Lesson 07thinkict
 
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesC# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesSami Mut
 
Open Office Calc : Lesson 05
Open Office Calc : Lesson 05Open Office Calc : Lesson 05
Open Office Calc : Lesson 05thinkict
 
Microsoft Project 2003 Configuration Training Level 2 Itvamp 2007
Microsoft Project 2003 Configuration Training Level 2 Itvamp 2007Microsoft Project 2003 Configuration Training Level 2 Itvamp 2007
Microsoft Project 2003 Configuration Training Level 2 Itvamp 2007ITVAMP, LLC
 
C# Tutorial MSM_Murach chapter-02-slides
C# Tutorial MSM_Murach chapter-02-slidesC# Tutorial MSM_Murach chapter-02-slides
C# Tutorial MSM_Murach chapter-02-slidesSami Mut
 
Open Office Calc : Level 1
Open Office Calc : Level 1Open Office Calc : Level 1
Open Office Calc : Level 1thinkict
 
Xamarin.Forms Hands On Lab (Begineer)
Xamarin.Forms Hands On Lab (Begineer)Xamarin.Forms Hands On Lab (Begineer)
Xamarin.Forms Hands On Lab (Begineer)Cheah Eng Soon
 

Mais procurados (19)

Chapter 05 show
Chapter 05 showChapter 05 show
Chapter 05 show
 
Chapter 03 - Program Coding and Design
Chapter 03 - Program Coding and DesignChapter 03 - Program Coding and Design
Chapter 03 - Program Coding and Design
 
Visual C# 2010
Visual C# 2010Visual C# 2010
Visual C# 2010
 
Cookbook Oracle SOA Business Rules
Cookbook Oracle SOA Business RulesCookbook Oracle SOA Business Rules
Cookbook Oracle SOA Business Rules
 
4.C#
4.C#4.C#
4.C#
 
Open Office Calc : Lesson 07
Open Office Calc : Lesson 07Open Office Calc : Lesson 07
Open Office Calc : Lesson 07
 
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesC# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slides
 
Open Office Calc : Lesson 05
Open Office Calc : Lesson 05Open Office Calc : Lesson 05
Open Office Calc : Lesson 05
 
SPF WinForm Programs
SPF WinForm ProgramsSPF WinForm Programs
SPF WinForm Programs
 
Microsoft Project 2003 Configuration Training Level 2 Itvamp 2007
Microsoft Project 2003 Configuration Training Level 2 Itvamp 2007Microsoft Project 2003 Configuration Training Level 2 Itvamp 2007
Microsoft Project 2003 Configuration Training Level 2 Itvamp 2007
 
C# Tutorial MSM_Murach chapter-02-slides
C# Tutorial MSM_Murach chapter-02-slidesC# Tutorial MSM_Murach chapter-02-slides
C# Tutorial MSM_Murach chapter-02-slides
 
Windowforms controls c#
Windowforms controls c#Windowforms controls c#
Windowforms controls c#
 
Tugas testing
Tugas testingTugas testing
Tugas testing
 
Open Office Calc : Level 1
Open Office Calc : Level 1Open Office Calc : Level 1
Open Office Calc : Level 1
 
Chapter03 Ppt
Chapter03 PptChapter03 Ppt
Chapter03 Ppt
 
Vb%20 tutorial
Vb%20 tutorialVb%20 tutorial
Vb%20 tutorial
 
Xamarin.Forms Hands On Lab (Begineer)
Xamarin.Forms Hands On Lab (Begineer)Xamarin.Forms Hands On Lab (Begineer)
Xamarin.Forms Hands On Lab (Begineer)
 
2 front panel
2  front panel2  front panel
2 front panel
 
Lab1
Lab1Lab1
Lab1
 

Semelhante a Chapter 08

EclipseCon 2009: TmL Tutorial Exercises
EclipseCon 2009: TmL Tutorial ExercisesEclipseCon 2009: TmL Tutorial Exercises
EclipseCon 2009: TmL Tutorial ExercisesEric Cloninger
 
Chapter2.ppt
Chapter2.pptChapter2.ppt
Chapter2.pptLalRatan
 
Vb net xp_11
Vb net xp_11Vb net xp_11
Vb net xp_11Niit Care
 
Mobile Worshop Lab guide
Mobile Worshop Lab guideMobile Worshop Lab guide
Mobile Worshop Lab guideMan Chan
 
02 asp.net session02
02 asp.net session0202 asp.net session02
02 asp.net session02Vivek chan
 
Debugger & Profiler in NetBeans
Debugger & Profiler in NetBeansDebugger & Profiler in NetBeans
Debugger & Profiler in NetBeansHuu Bang Le Phan
 
Creating a dot netnuke
Creating a dot netnukeCreating a dot netnuke
Creating a dot netnukeNguyễn Anh
 
The Ring programming language version 1.9 book - Part 82 of 210
The Ring programming language version 1.9 book - Part 82 of 210The Ring programming language version 1.9 book - Part 82 of 210
The Ring programming language version 1.9 book - Part 82 of 210Mahmoud Samir Fayed
 
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slidesC# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slidesSami Mut
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinFormHock Leng PUAH
 
Using Alf with Cameo Simulation Toolkit - Part 2: Modeling
Using Alf with Cameo Simulation Toolkit - Part 2: ModelingUsing Alf with Cameo Simulation Toolkit - Part 2: Modeling
Using Alf with Cameo Simulation Toolkit - Part 2: ModelingEd Seidewitz
 
PT1420 Modules in Flowchart and Visual Basic .docx
PT1420 Modules in Flowchart and Visual Basic             .docxPT1420 Modules in Flowchart and Visual Basic             .docx
PT1420 Modules in Flowchart and Visual Basic .docxamrit47
 
People code events 1
People code events 1People code events 1
People code events 1Samarth Arora
 

Semelhante a Chapter 08 (20)

Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
EclipseCon 2009: TmL Tutorial Exercises
EclipseCon 2009: TmL Tutorial ExercisesEclipseCon 2009: TmL Tutorial Exercises
EclipseCon 2009: TmL Tutorial Exercises
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
 
Chapter2.ppt
Chapter2.pptChapter2.ppt
Chapter2.ppt
 
Vb net xp_11
Vb net xp_11Vb net xp_11
Vb net xp_11
 
Mobile Worshop Lab guide
Mobile Worshop Lab guideMobile Worshop Lab guide
Mobile Worshop Lab guide
 
02 asp.net session02
02 asp.net session0202 asp.net session02
02 asp.net session02
 
Debugger & Profiler in NetBeans
Debugger & Profiler in NetBeansDebugger & Profiler in NetBeans
Debugger & Profiler in NetBeans
 
Creating a dot netnuke
Creating a dot netnukeCreating a dot netnuke
Creating a dot netnuke
 
The Ring programming language version 1.9 book - Part 82 of 210
The Ring programming language version 1.9 book - Part 82 of 210The Ring programming language version 1.9 book - Part 82 of 210
The Ring programming language version 1.9 book - Part 82 of 210
 
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slidesC# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slides
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
 
Csharp
CsharpCsharp
Csharp
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinForm
 
12 gui concepts 1
12 gui concepts 112 gui concepts 1
12 gui concepts 1
 
Ecad final
Ecad finalEcad final
Ecad final
 
Using Alf with Cameo Simulation Toolkit - Part 2: Modeling
Using Alf with Cameo Simulation Toolkit - Part 2: ModelingUsing Alf with Cameo Simulation Toolkit - Part 2: Modeling
Using Alf with Cameo Simulation Toolkit - Part 2: Modeling
 
PT1420 Modules in Flowchart and Visual Basic .docx
PT1420 Modules in Flowchart and Visual Basic             .docxPT1420 Modules in Flowchart and Visual Basic             .docx
PT1420 Modules in Flowchart and Visual Basic .docx
 
People code events 1
People code events 1People code events 1
People code events 1
 

Chapter 08

  • 1. CHAPTER EIGHT Using Procedures and Exception Handling
  • 2. Chapter 8: Using Procedures and Exception Handling 2 Objectives Create a splash screen Pause the splash screen Add a ComboBox object to a Windows Form Write Code for a SelectedIndexChanged event Code a Sub procedure
  • 3. Chapter 8: Using Procedures and Exception Handling 3 Objectives Pass an argument to a procedure by value Pass an argument to a procedure by reference Code a Function procedure to return a value Create a class-level variable Catch an exception using a Try-Catch block
  • 4. Chapter 8: Using Procedures and Exception Handling 4 Introduction As an application grows, it is important to divide each facet of a problem into separate sections of code called procedures Try-Catch blocks can check for any error a user might commit One way to make your programs more professional is to display a splash screen while the full program loads
  • 5. Chapter 8: Using Procedures and Exception Handling 5 Creating a Splash Screen Create a Windows application named Ocean Tours. Name the form frmTours. Click Project on the menu bar and then click Add New Item on the Project menu In the Add New Item dialog box, select Splash Screen in the center pane Click the Add button in the Add New Item dialog box Click the splash screen form in the left side of the form to select the form. To set the application to display the splash screen first, right-click OceanTours in the Solution Explorer Click Properties on the shortcut menu
  • 6. Chapter 8: Using Procedures and Exception Handling 6 Creating a Splash Screen In the Windows application framework properties section, click the Splash screen list arrow, and then click SplashScreen1 to select the form as the splash screen used for project Click the Assembly Information Button on the Properties Designer to open the Assembly Information dialog box To customize the splash screen, change the Title to Ocean Tours and the Copyright to the present year. The File Version can be changed as you update the application
  • 7. Chapter 8: Using Procedures and Exception Handling 7 Creating a Splash Screen Click the OK button on the Assembly Information dialog box. Close the OceanTours* Project Designer window.To change the predefined image, first download the ocean.jpg picture from the scsite.com/vb2010/ch8/images Web site and store the image in a location you remember. Then, click the SplashScreen1.vb [Design] tab. Click the left side of the splash screen, making sure to select the entire splash screen form.TheProperties window should identify MainLayoutPanel if you have selected the entire splash screen form. Click to the right of the Background Image property in the Properties window, and then click the ellipsis button. In the Select Resource dialog box, click the Project resource file radio button if necessary. Import the ocean.jpg picture by clicking the Import button in the Select Resource dialog box and selecting the ocean.jpg image from the location where you stored it. Click the OK button in the Select Resource dialog box Run the application by clicking the Start Debugging button on the Standard toolbar
  • 8. Chapter 8: Using Procedures and Exception Handling 8 Creating a Splash Screen
  • 9. Chapter 8: Using Procedures and Exception Handling 9 Pausing the Splash Screen After the splash screen loads, the application executes any code in the form load event handler. To display the splash screen for five seconds, the code that calls the Sleep procedure should be in the form load event handler. To open the code editor window and the form load event handler, double-click the background of the frmTours Windows Form object in the Design window Click inside the frmToursLoad event handler. Type Threading. To cause IntelliSense to display a list of possible entries. If necessary, type T to select Thread from the IntelliSense list. Type .S to select Sleep from the IntelliSense list. Type (5000)
  • 10. Chapter 8: Using Procedures and Exception Handling 10 Pausing the Splash Screen
  • 11. Chapter 8: Using Procedures and Exception Handling 11 Adding a ComboBox Object Drag the ComboBox .NET component from the Common Controls category of the Toolbox to the approximate location where you want to place the ComboBox object With the ComboBox object selected, scroll in the Properties window to the (Name) property. Double-click in the right column of the (Name) property and then enter the name cboIsland In the Properties window, scroll to the Text property. Click to the right of the Text property and enter Select Island Location: to specify the text that appears in the combo box. Resize the ComboBox object as needed to display the data in the box
  • 12. Chapter 8: Using Procedures and Exception Handling 12 Adding a ComboBox Object In the Properties window, scroll to the Items property, and click to the right of the Items property on the word (Collection). Click the ellipsis button. The String Collection Editor dialog box opens. Enter the island locations Aruba (press ENTER), Jamaica (press ENTER), and Key West In the String Collection Editor dialog box, click the OK button. Click the Start Debugging button on the Standard toolbar to run the application. Click the list arrow on the right of the ComboBox object to view the contents. You can select a choice from the list
  • 13. Chapter 8: Using Procedures and Exception Handling 13 Adding a ComboBox Object
  • 14. Handling SelectedIndexChanged Events Chapter 8: Using Procedures and Exception Handling 14
  • 15. Chapter 8: Using Procedures and Exception Handling 15 Handling SelectedIndexChanged Events Select the ComboBox object named cboIsland on the Windows Form object Double-click the ComboBox object. Close the Toolbox
  • 16. Chapter 8: Using Procedures and Exception Handling 16 Coding a Sub Procedure When a program is broken into manageable parts, each part is called a procedure A procedure is a named set of code that performs a given task A Sub procedure is a procedure that completes its task but does not return any data to the calling procedure A Sub procedure is the series of Visual Basic statements enclosed by the Sub and End Sub statements A Sub procedure is called with a statement consisting of the procedure name and a set of parentheses in the form of a procedure call
  • 17. Chapter 8: Using Procedures and Exception Handling 17 Coding a Sub Procedure
  • 18. Chapter 8: Using Procedures and Exception Handling 18 Coding a Sub Procedure
  • 19. Chapter 8: Using Procedures and Exception Handling 19 Passing Arguments
  • 20. Chapter 8: Using Procedures and Exception Handling 20 Passing Arguments by Value (ByVal) When a procedure is called, the call statement can pass an argument to the called procedure The value is copied into a variable whose name is specified in the Sub procedure declaration statement
  • 21. Chapter 8: Using Procedures and Exception Handling 21 Passing Arguments by Value (ByVal)
  • 22. Chapter 8: Using Procedures and Exception Handling 22 Passing Arguments by Value (ByVal)
  • 23. Chapter 8: Using Procedures and Exception Handling 23 Passing Arguments by Reference The second way in which to pass an argument from a calling procedure to a called Sub procedure is by reference You specify you want to pass a value by reference by entering the keyword ByRef in the Sub procedure declaration Passing a value by reference allows code in the Sub procedure to modify the contents of the variable that is being passed because when you use ByRef, you are passing a reference to the variable that holds the value instead of the value as when you use ByVal
  • 24. Chapter 8: Using Procedures and Exception Handling 24 Passing Arguments by Reference
  • 25. Chapter 8: Using Procedures and Exception Handling 25 Passing Arguments by Reference
  • 26. Chapter 8: Using Procedures and Exception Handling 26 Passing Multiple Arguments You can pass as many arguments as needed to a Sub procedure If you have more than one argument, the variables are passed in the same order in which they appear in the procedure call statement
  • 27. Chapter 8: Using Procedures and Exception Handling 27 Function Procedures A Function procedure is similar to a Sub procedure except that a Function procedure returns a single value to the calling procedure
  • 28. Chapter 8: Using Procedures and Exception Handling 28 Function Procedures The Function procedure is different in appearance from a Sub procedure in the following ways: The Function procedure call has a receiving variable that is assigned the returned value from the Function procedure The data type of the return value is listed in the procedure declaration The keyword Return is used in the Function procedure to return a single value
  • 29. Chapter 8: Using Procedures and Exception Handling 29 Function Procedures
  • 30. Chapter 8: Using Procedures and Exception Handling 30 Creating a Private Class-Level Variable When a class-level variable cannot be referenced outside the class in which it is declared, the variable is said to have Private access
  • 31. Chapter 8: Using Procedures and Exception Handling 31 Exception Handling The Try-Catch set of statements detects exceptions and takes corrective action
  • 32. Chapter 8: Using Procedures and Exception Handling 32 Exception Handling
  • 33. Chapter 8: Using Procedures and Exception Handling 33 Exception Handling
  • 34. Chapter 8: Using Procedures and Exception Handling 34 Exception Handling
  • 35. Chapter 8: Using Procedures and Exception Handling 35 Program Design
  • 36. Chapter 8: Using Procedures and Exception Handling 36 Program Design
  • 37. Chapter 8: Using Procedures and Exception Handling 37 Program Design
  • 38. Chapter 8: Using Procedures and Exception Handling 38 Program Design when using Sub and Function Procedures When a program becomes larger, often it is advantageous to break the program into procedures, which perform specific tasks within the program Makes the program easier to read, understand, and debug The developer must determine what code should be placed in a procedure. Procedures should: Perform a single task Perform reasonably substantial processing Use Sub and Function procedures appropriately
  • 39. Chapter 8: Using Procedures and Exception Handling 39 Event Planning Document
  • 40. Chapter 8: Using Procedures and Exception Handling 40 Event Planning Document
  • 41. Event Planning Document Chapter 8: Using Procedures and Exception Handling 41
  • 42. Event Planning Document Chapter 8: Using Procedures and Exception Handling 42
  • 43. Chapter 8: Using Procedures and Exception Handling 43 Summary Create a splash screen Pause the splash screen Add a ComboBox object to a Windows Form Write Code for a SelectedIndexChanged event Code a Sub procedure
  • 44. Chapter 8: Using Procedures and Exception Handling 44 Summary Pass an argument to a procedure by value Pass an argument to a procedure by reference Code a Function procedure to return a value Create a class-level variable Catch an exception using a Try-Catch block
  • 45. CHAPTER EIGHT COMPLETE Using Procedures and Exception Handling