PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Advertisements

Tutorial 12: Enhancing Excel with Visual Basic for Applications
An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
Chapter 8Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 8 l Basic Exception Handling »the mechanics of exceptions l.
Microsoft VB 2005: Reloaded, Advanced Chapter 5 Input Validation, Error Handling, and Exception Handling.
Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
CSI 3120, Exception handling, page 1 Exception and Event Handling Credits Robert W. Sebesta, Concepts of Programming Languages, 8 th ed., 2007 Dr. Nathalie.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Lec6 P 1 CP2030 Visual Basic For C++ programmers Copyright © University of Wolverhampton CP2030 VBFC Lecture 6 Back To Index v Procedures and Parameters.
Finding and Debugging Errors
Chapter 12: Advanced Topics: Exception Handling Visual Basic.NET Programming: From Problem Analysis to Program Design.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Debugging Logic Errors CPS120 Introduction to Computer Science Lecture 6.
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Microsoft Visual Basic 2005: Reloaded Second Edition
Debugging applications, using properties Jim Warren – COMPSCI 280 S Enterprise Software Development.
1 Chapter 9 Writing, Testing, and Debugging Access Applications.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Enhancing User Interaction Through Programming
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Teacher: Ms. Olifer MICROSOFT VISUAL STUDIO 2010: PROPERTIES OF WINDOWS FORM OBJECT.
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
Chapter 4: The Selection Process in Visual Basic.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
VB.Net - Exceptions Copyright © Martin Schray
Object Oriented Software Development 8. Exceptions, testing and debugging.
Introduction to Exception Handling and Defensive Programming.
Visual Basic.NET BASICS Lesson 5 Exponentiation, Order of Operations, and Error Handling.
VB – Debugging Tools Appendix D. Why do we need debugging? Every program has errors, and the process of finding these errors is debugging Types of errors.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
Computer Programming with JAVA Chapter 8. Exception Handling Basic Exception Handling the mechanics of exceptions Defining and Using Exceptions some "simple"
1.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Exceptions and Assertions Chapter 15 – CSCI 1302.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Debug in Visual Studio Windows Development Fundamentals LESSON 2.5A.
Controlling Program Flow with Decision Structures.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Visual Basic Fundamental Concepts
A variable is a name for a value stored in memory.
Programming in visual basic .net Visual Basic Building Blocks
VBA - Excel VBA is Visual Basic for Applications
Testing and Debugging.
Computer Programming I
Using Procedures and Exception Handling
VISUAL BASIC.
Visual Basic..
CIS16 Application Development Programming with Visual Basic
CS285 Introduction - Visual Basic
Presentation transcript:

PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5

In this chapter 2  Terminology You Must Know  Understanding Namespaces  Error Handling  Introduction to Debugging

Objects and Classes 3  Objects belong to classes  All objects with the same characteristics (data and functions) constitute one class.  A class and an object of that class has the same relationship as a data type and a variable  Declaring a class doesn’t create any objects, just as mere existence of data type int doesn’t create any variables.

Objects and Classes 4  A class serves only as a plan, or a template, or sketch of a number of similar things. It merely specifies what data and what functions will be included in objects of that class.  A class is thus a description of a no. of similar objects.  For instance, HUMAN is a class, and JOHN is its instance (object)

Understanding Members 5  In Visual Basic, the definition of a class may include properties, methods, and events. Collectively these parts of an object are known as its members.  The modifiers (such as Public and Private) that precede the member definition are used to control the access to the member.  For example, Private members cannot be accessed from VB code outside the class definition, but Public members can be. (discussed in Chapter 8)

Understanding Method Types 6  Methods are units of code within a class that perform a task, but they come in several different forms.  The following are all statements that indicate execution of a method:  Invoke a method  Call a function  Execute a procedure (or subroutine)  Fire an event  Each of these statements is a variation on the same thing but has a specific connotation.

Understanding Method Types 7  The two most common types of methods are functions and subroutines.  A function has a value, much like a mathematical function. A declaration at the end of the function declaration indicates the type of value returned by the function. (A function in VB also may have input parameters that control the return value.)  Unlike the function, the subroutine itself does not have a value. However, it can still send values back to the caller using output parameters.

Understanding Method Types 8 Private Function GetCurrentTime(Optional ByVal IncludeSeconds As Boolean = True) As String If IncludeSeconds = False Then Return Format(Now, "hh:mm") Else Return Format(Now, "hh:mm:ss") End If End Function Private Sub GetCurrentTime(ByRef CurrentTime As String, Optional ByVal IncludeSeconds As Boolean = True) If IncludeSeconds = False Then CurrentTime = Format(Now, "hh:mm") Else CurrentTime = Format(Now, "hh:mm:ss") End If End Sub

Understanding Method Types 9  The following lines of code show how to call the function and subroutine. In each case, the output value of the GetCurrentTime method is assigned to a string variable, ReturnValue. ReturnValue = GetCurrentTime(False) 'Calls the function GetCurrentTime(ReturnValue,False) 'Calls the sub

Understanding Events 10  An event is something external to your program e.g. when the user clicks a button he is causing an event.  Windows applications are inherently event-driven, meaning that the flow of program execution is controlled by the events that occur as the program is running.  The user or system can initiate events in any order. For example the user may click a button, scroll a list box, or close a window.

Selecting an Event Handler 11  The event handler is a special type of method that allows you to write code to respond to events.  When an event fires it executes the procedure that handles the event. When the user clicks a button he is causing an event within the program, so there is an associated method that handles that event.  When an object/event combination occurs at runtime and code has been written for that combination, Visual Basic executes the code. Otherwise, Visual Basic ignores the event.

Understanding Assembly & Namespace 12 The higher-level groupings (Above classes) :  An assembly provides a fundamental unit of physical code grouping. e.g.  Each time you create an Application, Service, Class Library, with Visual Basic.NET, you're building a single assembly. Each assembly is stored as an.exe or.dll file.

Understanding Assembly & Namespace 13  A namespace provides a fundamental unit of logical code grouping.  Namespaces do not replace assemblies, but. complement them Examples of Namespaces NamePurpose System.MathMathematical functions System.Drawing.GraphicsDrawing lines, and so on System.Windows.FormsWindows Forms System.Net.SocketsTCP Sockets

Error Handling 14  Syntax errors: are generally caught while you are typing the code and can be fixed easily because Visual Studio tells you it doesn't understand what you typed.  Logic errors: can usually appear only after you compile and run your code. They can be identified by incorrect operation of the program and are fixed by examining and then correcting an erroneously designed section of code e.g. division by zero  Runtime errors: usually occur due to reasons beyond programmer's control (hence an exception to the normal process and order of code execution) e.g. File not found

Structured Error Handling with Exceptions 15 An exception is thrown back to the function that called it. You can write code to catch the exception and then handle the error appropriately. Try File.Copy("myfile.txt", "yourfile.txt") MessageBox.Show("The file has been copied") Catch FileMissingError As FileNotFoundException Dim strMessage As String strMessage = FileMissingError.Message strMessage = strMessage & "Please make sure this file exists and try again.“ strMessage = strMessage & "The program will now exit.“ MessageBox.Show(strMessage, "Error has occurred", MessageBoxButtons.OK, MessageBoxIcon.Error) Application.Exit() End Try

Unstructured Error Handling with On Error Goto (old syntax) 16 Dim Answer As DialogResult = DialogResult.Retry On Error GoTo FileCopyError RetryHere: File.Copy("myfile.txt", "yourfile.txt") MessageBox.Show("The file has been copied") Answer = DialogResult.OK Exit Sub FileCopyError: Dim strMessage As String If Err.Number = 53 Then strMessage = "Missing file: " & Err.Description Else strMessage = "Error " & Err.Number & ": " & Err.Description End If Answer = MessageBox.Show(strMessage, "Error has occurred") If Answer = DialogResult.Retry Then Resume RetryHere Else Application.Exit() End If

Introduction to Debugging 17 To help track down bugs in your program, Visual Basic provides several tools:  Breakpoints tell the debugger that an application should break, pause execution, at a certain point. When a break occurs, your program and the debugger are said to be in break mode.  The Immediate window is used to debug and evaluate expressions, execute statements, print variable values, and so forth. It allows you to enter expressions to be evaluated or executed by the development language during debugging.  The Output window can display status messages for various features in the integrated development environment (IDE).  Watch You can use the Watch window to evaluate variables and expressions and keep the results. You can also use the Watch window to edit the value of a variable or register.

18 Q & A ?