Download presentation
Presentation is loading. Please wait.
Published byPatience Pitts Modified over 8 years ago
1
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Visual Basic Study #2 April 06, 2004 Kim, Ki Young (clowcard@sparcs.org)clowcard@sparcs.org Visual Basic Study Group SPARCS (http://sparcs.org) / KAIST (http://www.kaist.ac.kr)http://sparcs.orghttp://www.kaist.ac.kr 그림 : http://www.toriitraining.com/catfish.jpg
2
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems 목차 2. The Visual Basic.NET Language Assignment Operators and Expressions Statements Classes Interfaces We ’ ll be back ….
3
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Assignment Variable, field, or property = expression – 늘 해왔던 대로 … Value type –Expression 의 value 를 copy Reference type –Value 의 reference 를 저장
4
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Operators & Expressions Unary operators Binary operators Prefix notation –The operator precedes the operand –Unary operators Infix notation –The operator is between the operands –Binary operators –TypeOf.. Is??
5
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems O&E : Unary Operators +, - Not –Logical negation –Takes a Boolean operand AddressOf –Returns a reference to a method
6
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems O&E : Arithmetic Operations +, -, *, / \ (Integer division) –Integer operands –Rounded to the integer nearest to zero Mod –Modulo ^ –Exponentiation
7
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems O&E : Relational Operators, String-Concatenation Operators =, <>,, = TypeOf … Is –TypeOf Is –Return value : Boolean Is –Check if the references refer to the same object Like –Pattern Matching –?, *, #, [] String Concatenation –&, +
8
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems O&E : Bitwise Operators, Logical Operators And, Or, Xor, Not AndAlso –Check if both operands are True –Logical short-circuiting OrElse –Check if either or both operands are True –Logical short-circuiting Logical Operators –Boolean operands –And, Or, Xor, Not
9
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems O&E : Operator Precedence CategoryOperator Arithmetic and concatenation Exponentiation Negation Multiplication and division Integer division Modulus arithmetic Addition and subtraction, + & Comparison Operation … Logical and bitwise operators Negation (Not) Conjunction (And, AndAlso) Disjunction (Or, Orelse, Xor)
10
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems O&E : Operator Overloading.NET Framework Supports Operator Overloading, But current version of Visual Basic.NET doesn ’ t support operator overloading C# 으로 된 component 를 읽을 경우 ? – 다른 method 를 통해 같은 기능을 제공해야 함
11
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Statements Line breaks 를 통해 statement 가 끝남 여러 줄에 걸쳐 한 statement 를 작성할 경우 한 줄에 여러 statement 를 작성할 경우 : colon(:) Dim strSql As String = “SELECT Customers.CompanyName,” _ & “ COUNT(Orders.OrderID) AS OrderCount” _ & “ FROM Customers INNER JOIN Orders” _ … i = 5 : j = 10
12
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Statements : Option Statements BinaryOption Compare [Binary | Text] –Binary : Case-sensitive –Text : Case-insensitive OnOption Explicit [On | Off] –Decide if all variables need to be declared OffOption Strict [On | Off] –Check Type Conversion
13
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Statements : Branching Statements(1/3) Call() –Redundant!!! Exit –Exit Do –Exit For –Exit Function –Exit Property –Exit Sub –Exit Try
14
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Statements : Branching Statements(2/3) Goto – 여기서도 쓰지 않는 쪽을 권장 If If expression Then statements ElseIf expression Then statements ElseIf expression Then statements Else statements End If
15
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Statements : Branching Statements(3/3) RaiseEvent –Fires the given event Return –Exits a function and provides a return value Select Case Select Case strColor Case “red” ‘... Case “green”, “blue”, strSomecolor ‘... Case “purple” To “sky” ‘... Case Else ‘... End Select
16
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Statements : Iteration Statements Do For For Each Do While i<10 ‘... Loop ‘------------------ Do Until i>=10 ‘... Loop ‘------------------ Do ‘... Loop While i<10 ‘------------------ Do ‘... Loop For i = 1 To 10 For j = 1 To 10 For k = 1 To 10 ‘... Next k, j, i Dim a() As Integer = {1, 2, 3, 4, 5} Dim b As Integer For Each b In a ‘... Next
17
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Class : Object Instantiation and New 세 가지 방법이 모두 같은 결과 Imports System.Collections ‘No.1... Dim ht As Hashtable ht = New Hashtable() ‘No.2... Dim ht As Hashtable = New Hashtable() ‘No.3... Dim ht As New Hashtable()
18
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Class : Constructors Class 안에 New 라는 키워드를 통해 정의 Public Class SomeClass Dim m_value As Integer Public Sub New() m_value = Date.Today.Day ‘MyClass.New(Date.Today.Day) makes same result. End Sub Public Sub New(ByVal InitialValue As Integer) m_value = InitialValue End Sub End Class
19
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Class : Inheritance Class 는 Inherits 를 통해, Methods 는 Overrides 를 통해 상 속받는다. MustInherit : Instantiate 될 수 없음 MustOverride : derived class 에서 구현되어야 함 Parent Class 는 MyBase 를 통해 접근 Public Class Square Inherits Shape Public Overrides Sub Draw() ‘... End Sub End Class MyBase.New()
20
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Class : Methods Subroutines Functions [method_modifiers] Sub [attribute_list] _ method_name ([parameter_list]) [handles_or_implements] [method_body] End Sub [method_modifiers] Function [attribute_list] _ method_name ([parameter_list]) [As type_name] _ [handles_or_implements] [method_body] End Function
21
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Class : Method Parameters Parameter List Parameter 의 구성 [Optional] [ParamArray] [ByRef | ByVal] [attribute_list] _ parameter_name [As type_name] [ = constant expression] Parameter {, Parameter}
22
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Class : Main Method Compile 될 때 Main 이란 method 를 찾는다. Class 안에 있을 경우, Shared 로 되어있어야 한다. –Module 안에 있을 경우 Shared 라는 Keyword 가 필요 없음 여러 개의 Main 함수가 있을 경우 /main:
23
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Class : Implementing interface methods Implements 라는 keyword 사용 Public Class SomeClass Implements Icomparable Public Function CompareTo( _ ByVal obj As Object _ ) As Integer Implements Icomparable.CompareTo ‘... End Function End Class
24
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Class : Overloading 같은 기능, 다른 argument? – 굳이 함수 이름을 여러 개로 쓸 필요가 없다 Overloads? Overrides? Public Function SquareRoot(ByVal Value As Long) As Double ‘... End Function Public Function SquareRoot(ByVal Value As Double) As Double ‘... End Function
25
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Class : Shadowing Overloads Overrides => Shadows Public Class BaseClass Public Overridable Sub SomeMethod() ‘... End Sub Public Overridable Sub SomeMethod(ByVal i As Integer) ‘... End Sub End Class Public Class DerivedClass Inherits BaseClass Public Overloads Overrides Sub SomeMethod() ‘ = Public Shadows Sub SomeMethod() ‘... End Sub End Class
26
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Class : Property(1/2) Members that accessed like fields but are actually method calls Property Modifiers [property modifiers] Property [attributes] Property_name _ ([parameter list]) [As Type_Name] [implements list] [getter] [setter] End Property [Default] [access modifier] [override modifier] _ [overload modifier] [shared modifier] [read/write modifier]
27
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Class : Property(2/2) Public Property Center() As Point Get Dim retval As Point retval.X = Origin.X + (Size.XExtend \ 2) retval.Y = Origin.Y + (Size.YExtend \ 2) End Get Set Dim currentCenter As Point = Center Origin.X += Value.X – currentCenter.X Origin.Y += Value.Y – currentCenter.Y End Set End Property
28
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Class : The Me and MyClass Keywords Me, MyClass – 스스로의 Class 를 가리키는 keyword –MyClass 는 member access 에만 쓰일 수 있다. –Me 는 shared method 에서는 사용할 수 없다. Public Class BaseClass Public Sub Method1() Me.Method2() MyClass.Method2() End Sub Public Overridable Sub Method2() Console.WriteLine(“BaseClass.Method2”) End Class Public Class DerivedClass Inherits BaseClass Public Overrides Sub Method2() Console.WriteLine(“DeriveClass.Method2”) End Sub End Class
29
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Interfaces Interface 와 Class 의 member 의 이름이 일치할 필요 없음 Interface 상에 없는 member 도 Class 상에서 정의해줄 수 있음 한 Class 가 여러 Interface 를 상속받을 수 있음 Public Interface ISomeInterface Sub SomeSub() Function SomeFunction() As Integer Property Someproperty() As String Event SomeEvent( _ ByVal sender As Object, _ ByVal e As SomeEventArgs ) End Interface
30
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems To Be Continued … 제목 : Visual Basic Study #3 발표 : 전현우 (gosdnek@sparcs.org)gosdnek@sparcs.org 일시 : 다음주 초 ? 내용 : –2. The Visual Basic.NET Language Structures Enumerations Exceptions Delegates Events Standard Modules …
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.