Vb net
Download
1 / 68

VB - PowerPoint PPT Presentation


  • 134 Views
  • Updated On :

VB .NET. The Basics. The .NET Framework . Common Language Runtime Managed Code MS Intermediate Language – MSIL JIT Compiler Common Type System Common Language Specification Class Libraries – Namespace Multiple Language Support. Writing Windows Applications with VB.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'VB ' - crescent


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Vb net l.jpg

VB .NET

The Basics


The net framework l.jpg
The .NET Framework

  • Common Language Runtime

    • Managed Code

    • MS Intermediate Language – MSIL

    • JIT Compiler

  • Common Type System

  • Common Language Specification

  • Class Libraries – Namespace

  • Multiple Language Support


Writing windows applications with vb l.jpg
Writing Windows Applications with VB

  • Windows Graphical User Interface

    • VB.Net is an object-oriented language

    • Write application programs that run in Windows or on the Internet

  • Window = Form

  • Toolbox of elements called Controls

    • Text Box

    • Label

    • Check Box

    • Button


Programming languages l.jpg
Programming Languages

  • Procedural

    • Program specifies exact sequence

  • Event Driven (VB 6.0 and previous)

  • Object Oriented Programming (VB.NET)

    • User controls sequence

      • Click event

      • Double Click event

      • Change event


Object model l.jpg
Object Model

  • Object ==> Noun

    • Form and Controls

  • Property ==> Adjective

    • Color of a Form

  • Method ==> Verb

    • Move a Form


Object model cont l.jpg
Object Model (cont.)

  • Event ==> Occurs when the user takes action

    • User clicks a button, User moves a form

  • Class ==> Template to create new object

    • Each control added is an Instance of a Class


Dot notation l.jpg
Dot Notation

  • Used to reference object's properties and methods in code

    • Object dot Property

      • Form.Text, TextBox.Text

    • Object dot Method

      • Form.Hide( ), TextBox.Focus( )

  • To reference an object's events use an underscore instead of a dot

    • Button_Click, ListBox_TextChanged


Intellisense l.jpg
Intellisense

label1.FlatStyle =label1.Enter() label1.Equals()

Event

Method

Property


Vb application files l.jpg
VB Application Files

  • One Solution File .sln

    • May contain multiple projects

    • Stores the names of the project and config info

  • Solution User Options File .suo

    • User customization options

    • IDE screen layout

  • Project Files .vbproj

    • Describes the project and list the files required

    • May contain multiple forms

  • Project User Options File .vbproj.user

  • Form Files .vb /.aspx

  • Resource File for the Form .resx

  • Code Behind .aspx.vb


Visual studio environment l.jpg
Visual Studio Environment

  • Integrated Development Environment (IDE)

  • Form Designer

  • Editor for entering code

  • Compiler

  • Debugger

  • Object Browser






Ide main window l.jpg
IDE Main Window

  • Toolbars

  • Document Window

  • Form Designer

  • Solution Explorer

  • Properties Window

    • The Name property of a control is used to refer to the control in code.

    • The Text property holds the words that the user sees on the screen.

  • Toolbox



Vb toolbox l.jpg
VB Toolbox

  • Holds the controls you place on a form


Visual studio help l.jpg
Visual Studio Help

  • Extensive Help feature

  • Includes Microsoft Developer Network library (MSDN)

  • Entire reference manual

  • Coding examples

  • Dynamic Help

  • Technet

    • http://msdn.microsoft.com/library/en-us/vblr7/html/vboriVBLangRefTopNode.asp


Modes l.jpg
Modes

  • Design Time

    • Designing the interface and writing code

  • Run Time

    • Testing and running project

  • Break Time

    • Runtime error or pause

    • Debugging

“Look at the Title Bar”


Naming rules handout l.jpg
Naming Rules – Handout

  • Always use standard names for objects

  • Numbers, letters, & underscore

    • Must start with letter or underscore

  • No spaces or punctuation marks

  • 3 letter lowercase prefix identifies control type

    • Button-btn

    • Label-lbl

    • Form-frm

  • If multiple words capitalize 1st letter of each word – Camel casing

    • btnExitProgram


  • Recommended naming conventions for vb objects l.jpg

    Object Class Prefix Example

    Form frm frmDataEntry

    Button btn btnExit

    TextBox txt txtPaymentAmount

    Label lbl lblTotal

    Radio Button rad radBold

    CheckBox chk chkPrintSummary

    Horizontal ScrollBar hsb hsbRate

    Vertical ScrollBar vsb vsbTemperature

    PictureBox pic picLandscape

    ComboBox cbo cboBookList

    ListBox lst lstIndegredients

    Recommended Naming Conventions for VB Objects


    Steps for writing vb projects l.jpg
    Steps for Writing VB Projects

    • Design/Define the User Interface

      • Interface Design Planning Form

    • Plan/Set the Properties

      • Object and Properties Planning Form

    • Plan/Write the Code

      • Event Procedure Planning Form

    • One of each of the above for each *.vb form file

    • Test and Debug


    Form design plan l.jpg
    Form Design Plan

    EXIT

    PUSH ME


    Properties design plan l.jpg
    Properties Design Plan

    • Label

      • Name lblMessage

      • Text leave blank

    • Button 1

      • Name btnPush

      • Text Push Me

    • Button 2

      • Name btnExit

      • Text Exit

    • Form

      • Name frmHello

      • Text Hello World by your name


    Event design plan l.jpg

    btnPush_Click

    btnExit_Click

    Set lblMessage.text to “Hello World”

    Exit program

    Event Design Plan


    Set the project s startup object l.jpg
    Set the Project's Startup Object

    • The default startup object if Form1

    • The name of the form should always be changed to adhere to naming rules

    • Using Project menu, Properties change the startup object to match the new name


    Write the code l.jpg
    Write the Code

    • While the project is running the user can perform actions

    • Each action by the user causes an Event to occur

    • Write code for the events you care about, the events you want to respond with code

    • Code is written as event procedures

    • VB will ignore events for which you do not write code


    Editor window l.jpg
    Editor Window

    • Declarations Section

    • Class list

    • Method list


    Remark statement l.jpg
    Remark Statement

    • Also known as Comment, used for documentation

    • Non-executable

    • Automatically colored Green in Editor

    • Begins with an apostrophe ( ' )

      • On a separate line from executable code

      • At the right end of a line of executable code

    ' Display the Hello World message


    Test and debug l.jpg
    Test and Debug

    • Save Project - File Menu, Save All

    • Run Project

      • Debug Menu, Start (F5)

      • Start With Full without Debugging (CTRL F5)

    • Correct any Errors and Rerun

      • Compile errors

      • Run-Time Errors

      • Logic errors

      • Syntax errors

    "Help is always available from the Help Menu or by pressing F1."


    Finding and fixing errors l.jpg
    Finding and Fixing Errors

    • Syntax Errors

    • Run-Time Errors

    • Logic Errors


    Assignment statement l.jpg

    Assigns a value to a property or variable

    Operates from right to left

    Enclose text strings in quotation marks (" ")

    Assignment Statement

    lblMessage.Text=" Hello World "


    Ending a program l.jpg
    Ending a Program

    • Execute the Close Method of the Form

    • Methods always have parentheses (this will help you distinguish them from Properties which never have parentheses)

    • Current Form may be referenced as Me

    Me.Close( )


    Button btn l.jpg
    Button (btn)

    • Used to run/activate an Event Procedure

    • Click event

      Label (lbl)

    • Used for

      • Output on a form

      • Identification of objects

      • Directions/Information

    • Cannot by modified by user


    Text box txt l.jpg
    Text Box (txt)

    • Used for user input/data entry

    • Text Property

      • What is displayed in text box

      • What user entered in text box

    • TextAlign Property

      • Controls alignment of text in the Text Box

    • Change Event


    Check box chk l.jpg
    Check Box (chk)

    • Used for user input/data entry

    • Allows the user to select or deselect 1 or more in any group

    • Checked Property - Boolean

      • Checked = True

      • Unchecked = False

    • CheckChanged Event


    Radio button rad l.jpg
    Radio Button (rad)

    • Used for user input/data entry

    • Allows the user to select only 1 in any group

    • First create a group and then create each radio button inside the group

    • Checked Property - Boolean

      • Checked = True

      • Unchecked = False

    • CheckChanged Event




    Variables constants l.jpg
    Variables & Constants

    • Variable

      • Memory locations that hold data that can be changed during project execution

      • Ex: hours worked

    • Named Constant

      • Memory locations that hold data that cannot be changed during project execution

      • Ex: Sales tax percentage, SSI rate


    Constants l.jpg
    Constants

    • Named

      • User defined

    • Intrinsic

      • System defined within Visual Studio

        • Color.red


    Declaration statements l.jpg
    Declaration Statements

    • DIM|PUBLIC|PRIVATE|FRIEND|STATICused to declare Variables

    • CONST used to declare Named Constants

    • Declaration includes

      • Name, follow Naming Convention Rules

      • Data Type

      • Required Value for Constants

      • Optional Initial Value for Variables


    Declaration examples l.jpg
    Declaration Examples

    Dim strName, strSSN As String

    Dim intAge As Short

    Dim decPayRate As Decimal = 8.25

    Dim datHireDate As Date

    Dim blnInsured As Boolean

    Dim lngPopulation As Long

    Const decDISCOUNT_RATE As Decimal = .15

    Note: Constants are named using all uppercase letters EXCEPT the prefix.


    Type declaration characters l.jpg
    Type-Declaration Characters

    • Append single character to the end of the Constant's Value to indicate the Data Type

    Short – S

    Integer – I

    Long – L

    Decimal – D

    Single – F

    Double – R


    Variables scope lifetime l.jpg
    Variables – Scope & Lifetime

    • Global/Public (use sparingly and cautiously)

      • Available to all modules and procedures of Project

      • Initialized at start of Project

    • Module/Private (Form)

      • Available to one module and all procedures within that module

      • Initialized 1st time the Form is loaded

    • Local

      • Available only to the procedure it is declared in

      • Initialized every time the Procedure runs

    • Block (not used until later in this course)

      • Available only to the block of code inside a procedure it is declared in

      • Initialized every time the Procedure runs



    Calculations l.jpg
    Calculations

    • Calculations can be performed using properties of certain objects, variables, constants, and numeric literals

    • Do Not use Strings in calculations

    • Values from Text property of Text Boxes

      • Are Strings, even if they contain numeric data

      • Must be converted to a Numeric Data Type


    Conversion functions cont l.jpg
    Conversion Functions (cont.)

    • Function Convert To

    • CInt ** Integer

    • CDec Decimal

    • CStr String

    ** CInt rounds to the nearest Even Number


    Conversion examples also review info p 485 l.jpg
    Conversion Examples(also review info p 485)

    intQuantity = CInt(txtQuantity.Text)

    decPrice = CDec(txtPrice.Text)

    intWholeNumber = CInt(decFractionalValue)

    decDollars = CDec(intDollars)

    strValue = CStr(decValue)

    Function

    Name

    Argument

    To Be Acted Upon


    Mathematical operators l.jpg
    Mathematical Operators

    • Operator Operation

    • + Addition

    • – Subtraction

    • * Multiplication

    • / Division

    • \ Integer Division

    • Mod Modulus (division's remainder)

    • ^ Exponentiation


    Mathematical order of operations l.jpg
    Mathematical Order of Operations

    • Computers solve math formulas based on a specific order 1st, then left to right

      1. Parentheses

      2. Exponentiation

      3. Multiplication & Division

      4. Integer Division

      5. Modulus

      6. Addition & Subtraction


    Option explicit l.jpg
    Option Explicit

    • On by default - should be left on

    • If turned off

      • Variables can be used without first being declared

      • They will be defined by VB as data type Object

    • To turn off

      • Code OptionExplicit Off or Option Explicit in General Declarations

      • Set in Project Properties dialog box


    Option strict l.jpg
    Option Strict

    • Off by default - should be turned on

    • If turned on

      • VB becomes strongly typed language

      • Will not allow implicit conversions from a wider data type to a narrower one or between String and numeric data types

    • To turn on

      • Code OptionStrict On in General Declarations

      • Set in Project Properties dialog box

      • Required in all programs


    Formatcurrency function l.jpg
    FormatCurrency Function

    • General Form

      • FormatCurrency(NumericExpression)

    • Returns a string of characters formatted as dollars and cents

    • Includes a Dollar Sign, commas, and 2 decimal places by default

    • Value returned is a String and can no longer be used in calculations


    Formatnumber function pg 499 l.jpg
    FormatNumber Function – pg 499

    • General Form

      • FormatNumber(NumericExpression[ , Decimal Places [ , Leading Digit[ , Use Parentheses for Negative Numbers[ , Grouping for Digits] ] ] ] )

    • Formats with commas and specified number of decimal places (2 by default)

    Line Continuation not included on this slide


    Named formats formatdatetime function l.jpg

    Named Format Example

    DateFormat.GeneralDate 2/28/99 6:01:24 PM

    DateFormat.ShortDate 2/28/99

    DateFormat.LongDate Sunday, February 28, 1999

    DateFormat.ShortTime 18:01(24 Hour Clock)

    DateFormat.LongTime 6:01:24 PM

    Named Formats - FormatDateTime Function


    Handling exceptions l.jpg
    Handling Exceptions

    • Exceptions occur when user enters unexpected/invalid data and program code does not anticipate this possibility, such as

      • User enters nonnumeric data in Text Box and code attempts to run a Numeric Conversion Function

      • User enters data that results in division by zero


    Try catch blocks pg 488 l.jpg
    Try/Catch Blocks - pg 488

    • Used to catch and handle exceptions; referred to as error trapping or handling

    • Enclose statements that might cause an error within Try/Catch Block

      • If an error occurs control is transferred to the Catch Block

      • Include a Finally statement to indicate code that should execute last whether or not an exception occurred


    Try block general form l.jpg
    Try Block - General Form

    Try

    statements that may cause error

    Catch [VariableName as ExceptionType]

    statements for action when an exception occurs

    [Finally

    statements that always execute before exit of Try block]

    End Try

    See Help for list of common Exception Classes


    Try block example 1 catches all exceptions l.jpg
    Try Block - Example 1Catches All Exceptions

    Try

    intQuantity=CInt(txtQuantity.Text)

    lblQuantity.Text=CStr(intQuantity)

    Catch

    lblMessage.Text="Error in input data."

    End Try


    Try block example 2 catches specific exception l.jpg
    Try Block - Example 2Catches Specific Exception

    Try

    intQuantity=CInt(txtQuantity.Text)

    lblQuantity.Text=CStr(intQuantity)

    Catch MyErr as InvalidCastException

    lblMessage.Text="Error in input data."

    End Try

    Conversion exception, usually caused by nonnumeric or blank data


    Try block example 3 catches multiple specific exceptions l.jpg
    Try Block - Example 3Catches Multiple Specific Exceptions

    Try

    statements that may cause errors

    Catch MyErr as InvalidCastException

    error messages and statements for nonnumeric data Catch MyErr as ArithmeticException

    error messages and statements for calculation problems

    Catch MyErr as Exception

    error messages and statements for any other exception

    End Try


    Messagebox object l.jpg
    MessageBox Object

    • Use Show Method of MessageBox to display special type of window

    • Arguments of Show method

      • Message to display

      • Optional Title Bar Caption

      • Optional Button(s)

      • Optional Icon


    Messagebox syntax l.jpg
    MessageBox Syntax

    • The MessageBox is an Overloaded Method

      • Signatures correspond to the Argument list

      • There are multiple Signatures to choose from

      • Arguments must be included to exactly match one of the predefined Signatures

    MessageBox.Show (TextMessage, TitlebarText, _ MessageBoxButtons, MesssageBoxIcon)


    Messageboxbuttons constants l.jpg
    MessageBoxButtons Constants

    • OK

    • OKCancel

    • RetryCancel

    • YesNo

    • YesNoCancel

    • AbortRetryIgnore


    Messageboxicon constants l.jpg

    Asterisk

    Error

    Exclamation

    Hand

    Information

    None

    Question

    Stop

    Warning

    MessageBoxIcon Constants


    ad