An Introduction VB.NET2 - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

An Introduction VB.NET2

Description:

The only difference between the two is that functions send information back to ... 13: OnClick='Button_Click'/ p 14: /form 15: /body /html ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 24
Provided by: SUBBA9
Category:

less

Transcript and Presenter's Notes

Title: An Introduction VB.NET2


1
An Introduction VB.NET2
  • ASP.NET
  • http//sdetu/courses/csdc101/
  • Lecture 07
  • Tuesday, February 26, 2008

2
Agenda
  • Functions
  • Sub routines
  • Classes

3
Branching Logic Controls
  • Subroutines (sometimes called procedures)
  • Functions
  • The only difference between the two is that
    functions send information back to whatever
    called them, and subroutines don't.
  • Subroutine
  • Sub name (parameters)
  • code
  • End Sub

4
Example
  • 4 sub Page_Load(obj as object, e as eventargs)
  • 5 MultiplyNumbers(8,9)
  • 6
  • 7 MultiplyNumbers(4,12)
  • 8
  • 9 MultiplyNumbers(348,23)
  • 10 end sub
  • 11
  • 12 sub MultiplyNumbers(intA as integer, intB as
    integer)
  • 13 Response.Write(intA intB "ltbrgt")
  • 14 end sub

5
Function Example
  • 4 sub Page_Load(obj as object, e as eventargs)
  • 5 Response.Write(MultiplyNumbers(8,9)
    "ltbrgt")
  • 6
  • 7 Response.Write(MultiplyNumbers(4,12)
    "ltbrgt")
  • 8
  • 9 Response.Write(MultiplyNumbers(348,23)
    "ltbrgt")
  • 10 end sub
  • 11
  • 12 function MultiplyNumbers(intA as integer,
    intB as _
  • 13 integer) as Integer
  • 14 Return intA intB
  • 15 end function

6
Two ways of Returning a value
  • Using return statement
  • Assigning the return value to the function itself
  • 12 function MultiplyNumbers(intA as integer, intB
    as _
  • 13 integer) as integer
  • 14 MultiplyNumbers intA intB
  • 15 end function

7
Optional Parameters
  • VB.NET allows you to do this with the Optional
    keyword
  • function MultiplyNumbers(intA as integer,
    _optional intB as__ integer 3) as Integer
  • return intA intB
  • end function
  • Calling the above function
  • MultiplyNumbers(8)
  • MultiplyNumbers(8,9)

8
Event Handlers
  • Actions that may occur in your applicationa
    mouse click or a button press, for instance.
  • You do this by creating an event handler. The
    syntax is identical to that for a subroutine.
  • When an event is raisedmeaning the event has
    occurredit produces variables that describe the
    event.
  • Your event handler can use these variables to
    figure out what to do.

9
Example
  • 1 lt_at_ Page Language"VB" gt
  • 2
  • 3 ltscript runat"server"gt
  • 4 Sub Button_Click(Sender As Object, e As
    EventArgs)
  • 5 Response.Write("You clicked the button!")
  • 6 End Sub
  • 7 lt/scriptgt
  • 8
  • 9 lthtmlgtltbodygt
  • 10 ltform runat"server"gt
  • 11 ltaspbutton id"btSubmit" Text"Submit"
  • 12 runatserver
  • 13 OnClick"Button_Click"/gtltpgt
  • 14 lt/formgt
  • 15 lt/bodygtlt/htmlgt

represents the object that raised the event.
contains any information specific to the event
that occurred.
10
What is an Object?
  • Objects are real world entities.
  • Dosa
  • Fried Maggi
  • Teacher
  • Etc
  • Two characteristics of these are
  • State
  • Behaviour

11
What is state of Objects?
  • Dosa is cold.
  • Dosas Temperature.
  • Fried Maggi is too spicy
  • Spice Level in Maggi
  • State in software Objects are dependent on
  • Variables.
  • Objects Contained.

12
Behaviour of an Object
  • Teachers Phd
  • Depends on Teachers research interest.
  • Students exam preparation
  • Depends on the Cricket match schedule.
  • Behaviour of a software object is
  • Functions Exposed by the object.

13
Features of Object Orientation
  • Encapsulation
  • Hiding out stuff from others.
  • Ex Consider Mail as an object, now you have your
    personal mails ?
  • Modularity
  • Imagine each student getting a room.
  • A Room gives privacy and separates out behavior
    of these students.

14
In Programming terms
  • Encapsulation
  • Controlling access to your Variables.
  • Controlling access to your Methods.
  • Modularity
  • Source code of one program is independent.
  • A software can be constructed from many such
    modules.

15
Messages
  • In a class if you sit alone, you may get sleep.
  • So you interact with Next student. ?
  • Objects cannot exist independently in vacuum.
  • They may have to interact with some one. But
    How????

16
In programming terms
  • But objects are not complicated as humans.
  • Messages are usually passed as parameters to the
    method exposed by the object.
  • So Two Object communicate using behaviors.
  • Now this Message can also be an object.

17
Classes
  • Classes form a template for creating objects.
  • Why do you need classes?
  • Classes give you a generic way of defining
    multiple objects.
  • An Object in programming terms is an instance of
    a CLASS
  • Didnt Understand????

18
Example
  • Note a separate class called Student.
  • Student has two parts
  • State (i.e. currently XYZ)
  • Behaviour (i.e. returning Name and ID)
  • Look at how the message is passed.
  • Now with this template I can create n students
    who are similar to XYZ

19
Class
  • Everything in the .NET Framework and VB.NET is
    represented by classes
  • Syntax
  • Class name
  • subroutines, functions, and properties
  • End Class
  • Any variables declared in a class are known as
    properties of the class.
  • Access Levels
  • Public Allows the members to be globally
    accessible.
  • Protected - Limits the members access to the
    containing type and all classes derived from the
    containing type.
  • Private- Limits the members access to only the
    containing type.

20
Example
  • 4 Class Clock
  • 5 public Second as integer
  • 6 public Minute as integer
  • 7 public Hour as integer
  • 8
  • 9 sub SetTime(intSec as integer, intMin as
    integer, _
  • 10 intHour as integer)
  • 11 Second intSec
  • 12 Minute intMin
  • 13 Hour intHour
  • 14 end sub
  • 15 End Class
  • 16
  • 17 sub Page_Load(Sender as object, e as
    EventArgs)
  • 18 dim objClock as new Clock
  • 19
  • 20 objClock.Second 60
  • 21
  • 22 end sub

21
Example
  • In your ASP.NET page, you could do the following
  • Dim objClock as new Clock
  • objClock.SetTime(60,4,12) objClock.Second 59
  • Whats with new ?
  • It's used to initialize a new object.
  • One more form
  • dim objClock as Clock New Clock

22
Inheritance
  • You don't have to create entirely new classes
    when there's a similar one that already does what
    you want.
  • Class AnalogClock
  • Inherits Clock
  • private ClockWound as Boolean false
  • sub WindClock()
  • ClockWound true
  • end sub
  • End Class
  • In your ASP.NET page, you could do the following
  • dim objAnalogClock as new AnalogClock
    objAnalogClock.SetTime(60, 4, 12)
  • objAnalogClock.WindClock

23
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com