Programming in visual basic .net Visual Basic Building Blocks

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
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.
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
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
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.
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.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
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.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
1 JavaScript in Context. Server-Side Programming.
Introduction to Exception Handling and Defensive Programming.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
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.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
Controlling Program Flow with Decision Structures.
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.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
IS 350 Course Introduction. Slide 2 Objectives Identify the steps performed in the software development life cycle Describe selected tools used to design.
Visual Basic Fundamental Concepts
Programming Right from the Start with Visual Basic .NET 1/e
Visual Basic.NET Windows Programming
A variable is a name for a value stored in memory.
Chapter 2: The Visual Studio .NET Development Environment
Debugging and Handling Exceptions
VBA - Excel VBA is Visual Basic for Applications
ME 142 Engineering Computation I
Chapter 1: An Introduction to Visual Basic 2015
Chapter 8: Writing Graphical User Interfaces
Testing and Debugging.
3.01 Apply Controls Associated With Visual Studio Form
Computer Programming I
Debugging CMSC 202.
3.01 Apply Controls Associated With Visual Studio Form
Microsoft Access Illustrated
Using Procedures and Exception Handling
Programmazione I a.a. 2017/2018.
Important terms Black-box testing White-box testing Regression testing
Important terms Black-box testing White-box testing Regression testing
Variables and Arithmetic Operations
VISUAL BASIC.
Visual Basic..
Hands-on Introduction to Visual Basic .NET
CIS16 Application Development Programming with Visual Basic
Part B – Structured Exception Handling
Tonga Institute of Higher Education
CS285 Introduction - Visual Basic
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look
Tonga Institute of Higher Education
Microsoft Visual Basic 2005 BASICS
Debugging and Handling Exceptions
Standard Version of Starting Out with C++, 4th Edition
Presentation transcript:

Programming in visual basic .net Visual Basic Building Blocks Bilal Munir Mughal Chapter-5

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

Objects and Classes 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 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 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 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 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 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) CurrentTime = Format(Now, "hh:mm") Else CurrentTime = Format(Now, "hh:mm:ss") End Sub

Understanding Method Types 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 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 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. The object is selected in the Code window's upper-left drop-down list box (the Class box); the appropriate event procedure is selected in the upper-right drop-down list box (the Method box). you enter a Code window by double-clicking an object, the Code window automatically selects that object's most commonly used event procedure. For example, if you double-click a command button at design time, the Code window is opened to that command button's Click event procedure.

Understanding Assembly & Namespace 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. The .NET Framework uses assemblies as the fundamental unit for several purposes: Security Type Identity Reference Scope Versioning Deployment

Understanding Assembly & Namespace A namespace provides a fundamental unit of logical code grouping. Namespaces do not replace assemblies, but complement them. Examples of Namespaces Name Purpose System.Math Mathematical functions System.Drawing.Graphics Drawing lines, and so on System.Windows.Forms Windows Forms System.Net.Sockets TCP Sockets Imports System.Net Dim skListen As System.Net.Sockets.Socket or Dim skListen As Socket

Error Handling 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 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) 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 Application.Exit() When an error has occurred, you use one of several statements to control the flow of the program: Exit the subroutine after informing the user of the error, with the Exit Sub statement. Use a Resume label statement to jump to another portion of code Use a Resume Next statement to continue executing on the line following the error.

Introduction to Debugging 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.

Q & A ?