Visual Basic .NET
Download
Report
Transcript Visual Basic .NET
Visual Basic .NET
CSC 415 – Programming Languages
November 18, 2014
Mi Gyeong Gwak
HISTORY OF BASIC
BASIC (Beginner's All-purpose Symbolic Instruction Code)
John Kemeny and Thomas Kurtsz
Dartmouth College in 1964
General Electric 225
Interpreted BASIC
http://www.q7basic.org/History%20of%20BASIC.pdf
•
•
•
•
•
•
•
•
general purpose
easy of use
expandable
Interactive
with debugging help
efficient
hardware independent
OS independent.
HISTORY OF VISUAL BASIC
Microsoft revived BASIC in 1991 (Visual Basic 1.0)
Visual Basic 6.0 in 1998
Object oriented
Event driven
Overcoming the limitations of being interpreted
Allowing programmers to generate a compiled executable code
http://www.max-visual-basic.com/history-of-visual-basic.html
NAMES
Begin with an alphabetical character or an underscore
Less than 1023 characters long
Case-insensitive
Reserved keywords
Escaped names are enclosed by brackets ([ ])
Unreserved keywords
SCOPES
BLOCK SCOPE
Do and Loop
For [Each] and Next
If and End If
Select and End Select
SyncLock and End SyncLock
Try and End Try
While and End While
With and End With
If n < 1291 Then
Dim cube As Integer
cube = n ^ 3
End If
SCOPES
Procedure scope
Module scope
Within modules, classes, structures
Private modifier
Namespace scope
Throughout the namespace
Friend or Public modifier
Private strMsg As String
Sub initializePrivateVariable()
strMsg = "This variable cannot be used outside this
module."
End Sub
Sub usePrivateVariable()
MsgBox(strMsg)
End Sub
DATA TYPES - Numeric
Integral Types
Non-integral Types
SByte (8-bit)
Decimal (128-bit fixed point)
Short (16-bit)
Single (32-bit floating point)
Integer (32-bit)
Double (64-bit floating point)
Long (64-bit)
Byte (8-bit)
UShort (16-bit)
UInteger (32-bit)
ULong (64-bit)
DATA TYPES – Character & Miscellaneous
Char
String
Boolean
Date
Object
DATA TYPES - Composite
Structures
Arrays
Classes
Constants
Enumerations
Dim airTemperatures(99, 99, 24) As Single
Dim twoSidedCube = {{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}}
OPERATORS
Dim lResult, rResult As Integer
Dim pattern As Integer = 12
' The low-order bits of pattern are 0000 1100.
lResult = pattern << 3
' A left shift of 3 bits produces a value of 96.
Arithmetic operations
rResult = pattern >> 2
Bit-shift operators (>> operator or << 'operator)
A right shift of 2 bits produces value of 3.
Comparison Operators
< > operator
Like operator
Is operator or IsNot operator
TypeOf Operator
testCheck = "F" Like "[A-Z]“
' The following statement returns True (does "F" occur in the set of
' characters from "A" through "Z"?)
OPERATORS
Concatenation operators
+ operator
& operator
Logical operators
Not operator
And operator
Or operator
Xor operator
AndAlso operator
OrElse operator
Dim a, b, c, d, e, f, g As Boolean
a = 23 > 14 And 11 > 8
b = 14 > 23 And 11 > 8
' The preceding statements set a to True and b to False.
c = 23 > 14 Or 8 > 11
d = 23 > 67 Or 8 > 11
' The preceding statements set c to True and d to False.
e = 23 > 67 Xor 11 > 8
f = 23 > 14 Xor 11 > 8
g = 14 > 23 Xor 8 > 11
' The preceding statements set e to True, f to False, and g to False.
CONTROL FLOW – Decision Structures
If…Then…Else construction
Select…Case construction
Try…Catch…Finally construction
Dim count As Integer = 0
Dim message As String
If count = 0 Then
message = "There are no items."
ElseIf count = 1 Then
message = "There is 1 item."
Else
message = "There are " & count & " items."
End If
CONTROL FLOW – Loop Structure
While…End While construction
Do…Loop construction
For…Next construction
For Each…Next construction
' Create a list of strings by using a
' collection initializer.
Dim lst As New List(Of String) _
From {"abc", "def", "ghi"}
' Iterate through the list.
For Each item As String In lst
Debug.Write(item & " ")
Next
Debug.WriteLine("")
'Output: abc def ghi
Support for Object Oriented
Programming
Abstraction
Encapsulation
Polymorphism
Inheritance
http://msdn.microsoft.com/en-us/library/aa289512(v=vs.71).aspx
CONCURRENCY EXCEPTIONS
DBConcurrencyException
Try
CustomersTableAdapter.Update(NorthwindDataSet)
Catch ex As DBConcurrencyException
Dim customErrorMessage As String
customErrorMessage = "Concurrency violation" & vbCrLf
customErrorMessage += CType(ex.Row.Item(0), String)
MessageBox.Show(customErrorMessage)
' Add business logic code to resolve the concurrency violation...
End Try
http://msdn.microsoft.com/en-US/library/y8fyz6xy(v=vs.80).aspx
EVENTS AND EVENT HANDLERS
Event keyword
RaiseEvent statement
WithEvents statement and Handles clause
AddHandler and RemoveHandler statements
Friend WithEvents Button1 As System.Windows.Forms.Button
Protected Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
End Sub
http://msdn.microsoft.com/en-us/library/2z7x8ys3(v=vs.90).aspx
ERROR TYPES
Syntax errors
Run-time errors
Logic errors
DEMO
Visual Studio 2013
http://www.youtube.com/watch?v=DF2fCWLFSG0
READABILITY
English-like appearance
Keywords that control structures and data types are using a clear
language
Initial and terminal statements of control structures
KEYWORDS
AddHandler
Auto
CBool
AndAlso
ByVal
CDec
Double
End
Event
Implements
Integer
Like
Next
NotOverridable
Optional
RaiseEvent
RemoveHandler
Set
Then
AddressOf
Ansi
CByte
CDbl
CLng
Dim
Each
Enum
GoTo
Imports
Interface
MyClass
Not
Object
Property
ReadOnly
Resume
Structure
Throw
Alias
Case
CChar
Char
Declare
DirectCast
Else
WRITABILITY
Visual programming language
Integrated Development Environment (IDE) - Visual Studio
Control structure is intuitive
Correct termination for each initialization
Dim statement
Dim My_Counter As Integer
RELIABILITY
Integer overflow checking
Option Strict statement
Structured exception
Try…Catch…Finally control structure
Unstructured exception
On Error Go To statement
Resume statement
Error statement
COST
Microsoft Visual Studio 2013
Visual Studio Express Edition 2013
Migration from Visual Basic 6.0 to .NET
ArtinSoft’s Visual Basic Upgrade Companion
Great Migrations Studio
VB Migration Partner tool
CONCLUSION