VB NET Revisit 1 Software Development Life Cycle
VB. NET Revisit 1
Software Development Life Cycle • • Problem Definition Requirement Analysis Systems Design Implementation Testing & Debugging Deployment Maintenance VB. NET Revisit 2
VB. NET • • . NET CLR-compliant language Event-driven Object Oriented Visual Studio. NET – A Rapid Application Development (RAD) environment – An Integrated Development Environment (IDE) • Editor, Command. VBLine Compiler. NET Revisit 3
Building Hello. World with Visual Studio. NET VB. NET Revisit 4
Hello World - Console Imports System ‘ import System namespace Public Module Hello ‘ a Standard Module Public Sub Main() Console. Write. Line("Hello World!") End Sub End Module • A Console application • To compile (by command line compiler): – vbc Hello. World. vb • To execute: – Hello. World. exe VB. NET Revisit 5
Hello World - GUI Imports System. Drawing Imports System. Windows. Forms ' import System namespace Public Class Hello. Windows Inherits Form ' inherits System. Windows. Form Private lbl. Hello. Windows As Label Public Shared Sub Main() Application. Run(New Hello. Windows()) End Sub Public Sub New() ' constructor lbl. Hello. Windows = New Label() With lbl. Hello. Windows. Location = New Point(37, 31). Size= New Size(392, 64). Font = New Font("Arial", 36). Text = "Hello, Windows!". Tab. Index = 0. Text. Align = Content. Alignment. Top. Center End With Me. Text = "Visual Basic. NET" Auto. Scale. Base. Size = New Size(5, 13) Form. Border. Style = Form. Border. Style. Fixed. Single Client. Size = New Size(466, 127) Controls. Add(lbl. Hello. Windows) End Sub End Class VB. NET Revisit 6
Hello World - GUI • A Windows Application • To compile: – vbc Hello. World 2. vb /reference: System. dll, System. Drawing. dll, Syst em. Windows. Forms. dll /target: winexe • To execute: – Hello. World 2. exe VB. NET Revisit 7
Class Public Class Student … End Class ‘ a base class Public Class Ft. Student Inherits Student … End Class Dim s 1 As New Student() Dim s 2 As New Ft. Student() s 1 = s 2 VB. NET Revisit 8
Access Modifiers • Control the accessibility of types and types members (including fields, methods, etc. ) Public Class Some. Class Public Sub Do. Something() End Sub Private Sub Internal. Helper. Sub() End Sub End Class • • Control the accessibility of types and types members (including fields, methods, etc. ) Private: accessible only from within the context in which it is declared Protected: from within the program in which it is defined and the derived classes Public: publicly accessible VB. NET Revisit 9
Fundamental Types • • • Boolean Byte Short Integer Long Decimal Single Double Char String Date Object VB. NET Revisit 10
Variables, Literals • • Dim b. Flag As Boolean = False Dim dat. Today As Date = #01/01/2005# Dim i. Value As Integer Dim l. Value As Long Dim sh. Value As Short = 128 Dim sng. Value As Single Dim dbl. Value As Double Dim My. String As String VB. NET Revisit 11
Type Conversion • Implicit Type Conversion: – Char -> String – Byte -> Short -> Integer -> Long -> Decimal -> Single -> Double • Explicit Type Conversion (Casting): – – – CByte() CShort() CInt() CLng() CDec() CSng() CDbl() CBool() CChar() CStr() CDate() VB. NET Revisit 12
Assignment Statements Dim a, b As Some. Class a = New Some. Class() a. My. Public. Member = “value in a” b=a b = New Some. Class() VB. NET Revisit 13
Operators • • +, -, *, / (integer division) Mod (modulo), 9 Mod 2 ^ (exponentiation), X^2 =, <>, <, <=, >, >=, AND, OR, NOT, XOR Type. Of …Is, Type. Of(x) Is String Is, s 1 Is s 2 Like, s 1 Like "a*“ VB. NET Revisit 14
Basic I/O Module 1 Sub Main() Dim n As Integer Dim s As String Console. Out. Write. Line("Hello. World! What's your name? ") s = Console. In. Read. Line() ‘ read in a string Console. Out. Write. Line("How old are you? ") n = Console. In. Read. Line() ‘ read in a number Console. Out. Write. Line("Hi " + s + ", you're " + CStr(n) + " already. ") ‘ or Console. Out. Write. Line("Hi {0}, you're {1} already. ", s, n) Console. In. Read. Line() ‘ wait to press Enter End Sub End Module VB. NET Revisit 15
Branching Statements (1) • • • Call Some. Method() or Some. Method() Exit Do, Exit For, Exit Function, Exit Sub, Exit Try If A = B Then statements End If If A = B Then statements Else. If expression Then statements Else statements End If VB. NET Revisit 16
Branching Statements (2) Select Case str. Color Case “red” … Case “green”, “blue” … Case Else … End Select VB. NET Revisit 17
Loop Do While I < 10 … Loop Do … Loop Until I >= 10 For i = 0 to 4 Step 2 Console. Write. Line(i) Next For Each i in i. Arrary … Next ‘ i. Arrary is an array For Each obj In col ‘ col is a collection Console. Write. Line(obj. To. String()) Next VB. NET Revisit 18
Array Dim a(4) As Integer For i = 0 to 4 Console. Write. Line(a(i)) Next Dim a() As Integer a = New Integer(2) {} a(0) = 1 a(1) = 2 Dim a() As String = {“First”, “Second”, “Third”} Dim a(5, 10) As Integer VB. NET Revisit 19
Enumeration Module 1 Enum Card. Suit clubs = 0 diamonds = 1 hearts = 2 spades = 3 End Enum Sub Main() Dim cs As Card. Suit = Card. Suit. hearts System. Console. Out. Write. Line("The value cs is {0}", cs) End Sub End Module VB. NET Revisit 20
Structure Module 1 Structure Pixel. Coord Public x As Single Public y As Single End Structure Sub Main() Dim p As Pixel. Coord p. x = 200 p. y = 100 System. Console. Out. Write. Line("The value p. x is {0}", p. x) System. Console. Out. Write. Line("The value p. y is {0}", p. y) End Sub End Module VB. NET Revisit 21
Collection Dim col As New Collection() col. Add(“First item”) col. Add(“Second item”) col. Add(“Third item”) Dim obj As Object For Each obj In col Console. Write. Line(CType(obj, String)) Next Dim i As Integer For i = 1 to col. Count Console. Write. Line(CType(col(i), String)) Next VB. NET Revisit 22
Sub & Function Sub Check. Input() … End Sub Function Square(By. Val i as Integer) As Integer … Return x End Function VB. NET Revisit 23
- Slides: 23