Download presentation
Presentation is loading. Please wait.
1
VB .NET Revisit VB .NET Revisit
2
Software Development Life Cycle
Problem Definition Requirement Analysis Systems Design Implementation Testing & Debugging Deployment Maintenance VB .NET Revisit
3
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 Line Compiler VB .NET Revisit
4
Building HelloWorld with Visual Studio .NET
VB .NET Revisit
5
Hello World - Console A Console application
Imports System ‘ import System namespace Public Module Hello ‘ a Standard Module Public Sub Main() Console.WriteLine("Hello World!") End Sub End Module A Console application To compile (by command line compiler): vbc HelloWorld.vb To execute: HelloWorld.exe VB .NET Revisit
6
Hello World - GUI VB .NET Revisit
Imports System ' import System namespace Imports System.Drawing Imports System.Windows.Forms Public Class HelloWindows Inherits Form ' inherits System.Windows.Forms.Form Private lblHelloWindows As Label Public Shared Sub Main() Application.Run(New HelloWindows()) End Sub Public Sub New() ' constructor lblHelloWindows = New Label() With lblHelloWindows .Location = New Point(37,31) .Size= New Size(392,64) .Font = New Font("Arial",36) .Text = "Hello, Windows!" .TabIndex = 0 .TextAlign = ContentAlignment.TopCenter End With Me.Text = "Visual Basic .NET" AutoScaleBaseSize = New Size(5, 13) FormBorderStyle = FormBorderStyle.FixedSingle ClientSize = New Size(466,127) Controls.Add(lblHelloWindows) End Class VB .NET Revisit
7
Hello World - GUI A Windows Application To compile: To execute:
vbc HelloWorld2.vb /reference:System.dll,System.Drawing.dll,System.Windows.Forms.dll /target:winexe To execute: HelloWorld2.exe VB .NET Revisit
8
Class Public Class Student ‘ a base class … End Class
Public Class FtStudent Inherits Student Dim s1 As New Student() Dim s2 As New FtStudent() s1 = s2 VB .NET Revisit
9
Access Modifiers Control the accessibility of types and types members (including fields, methods, etc.) Public Class SomeClass Public Sub DoSomething() End Sub Private Sub InternalHelperSub() 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
10
Fundamental Types Boolean Byte Short Integer Long Decimal Single
Double Char String Date Object VB .NET Revisit
11
Variables, Literals Dim bFlag As Boolean = False
Dim datToday As Date = #01/01/2005# Dim iValue As Integer Dim lValue As Long Dim shValue As Short = 128 Dim sngValue As Single Dim dblValue As Double Dim MyString As String VB .NET Revisit
12
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
13
Assignment Statements
Dim a, b As SomeClass a = New SomeClass() a.MyPublicMember = “value in a” b = a b = New SomeClass() VB .NET Revisit
14
Operators +, -, *, / \ (integer division) Mod (modulo), 9 Mod 2
^ (exponentiation), X^2 =, <>, <, <=, >, >=, AND, OR, NOT, XOR TypeOf …Is, TypeOf(x) Is String Is, s1 Is s2 Like, s1 Like "a*“ VB .NET Revisit
15
Basic I/O Module Module1 Sub Main() Dim n As Integer Dim s As String
Console.Out.WriteLine("HelloWorld! What's your name?") s = Console.In.ReadLine() ‘ read in a string Console.Out.WriteLine("How old are you?") n = Console.In.ReadLine() ‘ read in a number Console.Out.WriteLine("Hi " + s + ", you're " + CStr(n) + " already.") ‘ or Console.Out.WriteLine("Hi {0}, you're {1} already.", s, n) Console.In.ReadLine() ‘ wait to press Enter End Sub End Module VB .NET Revisit
16
Branching Statements (1)
Call SomeMethod() or SomeMethod() Exit Do, Exit For, Exit Function, Exit Sub, Exit Try If A = B Then statements End If Else ElseIf expression Then VB .NET Revisit
17
Branching Statements (2)
Select Case strColor Case “red” … Case “green”, “blue” Case Else End Select VB .NET Revisit
18
Loop Do While I < 10 … Loop Do Loop Until I >= 10
For i = 0 to 4 Step 2 Console.WriteLine(i) Next For Each i in iArrary ‘ iArrary is an array For Each obj In col ‘ col is a collection Console.WriteLine(obj.ToString()) VB .NET Revisit
19
Array Dim a(4) As Integer For i = 0 to 4 Console.WriteLine(a(i)) Next
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
20
Enumeration Module Module1 Enum CardSuit clubs = 0 diamonds = 1
hearts = 2 spades = 3 End Enum Sub Main() Dim cs As CardSuit = CardSuit.hearts System.Console.Out.WriteLine("The value cs is {0}", cs) End Sub End Module VB .NET Revisit
21
Structure Module Module1 Structure PixelCoord Public x As Single
Public y As Single End Structure Sub Main() Dim p As PixelCoord p.x = 200 p.y = 100 System.Console.Out.WriteLine("The value p.x is {0}", p.x) System.Console.Out.WriteLine("The value p.y is {0}", p.y) End Sub End Module VB .NET Revisit
22
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.WriteLine(CType(obj, String)) Next Dim i As Integer For i = 1 to col.Count Console.WriteLine(CType(col(i), String)) VB .NET Revisit
23
Sub & Function Sub CheckInput() … End Sub
Function Square(ByVal i as Integer) As Integer Return x End Function VB .NET Revisit
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.