วันจันทร์ที่ 11 เมษายน พ.ศ. 2554

ASP.NET : Easy Visual Basic Part I

ASP.NET Textbooks shop

ASP.NET and VB

ASP.NET is the next generation of Active Server Pages (ASP) although ASP.NET will be called from ASP, but the two technologies are completely different. By Microsoft that has created a new ASP.NET based out of the Common Language Runtime (CLR), which allows developers to use any language supported by the Dot Net framework such as C # and VB. NET, etc. Currently the latest version of ASP.NET 4.0 which is included in the. NET Framework 4.0. And our chosen programming language for writing code in ASP.NET

ASP.NET Programming with VB


ASP.NET : Variable

Variable is a symbolic name associated with a value and whose associated value may be changed
Dim StatementThe Visual Basic compiler uses the Dim statement to determine the variable's data type and other information, such as what code can access the variable. The following example declares a variable to hold an Integer value.



Type

Mean

Example

Boolean

Boolean which is true and False.

Dim myBoolean1 As Boolean


Dim myBoolean2 As Boolean


myBoolean1 = True


myBoolean2 = False

Char

Represents a Unicode character

Dim myChar As Char


myChar = "C"

String

String message store.

Dim myString As String


myString = "Mr.Weerachai Nukitram"

Date

Keep the date format.

Dim myDate As Date


myDate = #12/12/2008#

DateTime

DateTime format stores the date and time

Dim myDateTime As DateTime


myDateTime = #12/12/2008 18:00:00#

Decimal

Decimal number stored with decimal

Dim myDecimal As Decimal


myDecimal = 123.456

Double

Represents a double-precision floating point number

Dim myDouble As Double


myDouble = 123.456

Integer

Integer store integer.

Dim myInteger As Integer


myInteger = 123

Long

Represents a 64-bit signed integer.

Dim myLong As Long


myLong = 123456.789

Object

Object Storage object or Object.

Dim myObject As Object


myObject = Object

Short

Represents a 16-bit signed integer.

Dim myShort As Short


myShort = 123456.789

Single

Represents a single-precision floating point number.

Dim mySingle As Single


mySingle = 1.0231

Array

Array variables keep the same group.

Dim myArray(2) as Integer

myArray(0) = 1

myArray(1) = 4

myArray(2) = 5



Dim myArray(2,2) as Integer

myArray(0,0) = 1

myArray(0,1) = 3

myArray(0,2) = 4

myArray(1,0) = 0

myArray(1,1) = 1

myArray(1,2) = 10

myArray(2,0) = 9

myArray(2,1) = 7

myArray(2,2) = 8

ASP.NET : Sub Procedure

ASP.NET Sub Procedure is part of a program that works within the Sub itself is reason to want to separate program running as a proportion Because of the variable Sub will not affect other parts of the program code to create the Sub can not be restored to Return to One can change the values ​​on the Argument ByRef.

Syntax
Sub mySub
.......
End Sub

Example
Sub MySub()
Me.lblText.Text = "Welcome To My World"
End Sub

ASP.NET : Function

ASP.NET Function is part of a program that works within itself and to Return values Back to the Call Function.

Syntax
Function myFunction
...
Return Value
End Sub

Example
Function MyFunction(ByVal num1 As Integer,ByVal num2 As Integer)
Return num1+num2
End Function


ASP.NET : ByRef & ByVal

ByRef and ByVal are supported Argument Argument Passing and Function in Sub used to deal with external variables into the work of the Sub and Function control to change the value of the variable , And fault-tolerance variable is returned.

ByRef = allowed to change the value of the variable that send in to Sub or Function Argument when Called.
ByVal = not allowed to change the value of the variable that send in to Sub or Function Argument when Called.

Example
Function MyFunction(ByVal num1 As Integer,ByRef num2 As Integer)
Return num1+num2
End Function


ASP.NET : Protected

Protected is scope of Method, Sub / Function that can run only in it's Sub / Function or class.
If another Class want to call it Can be run by Inherits Class.

Syntax
Public Class myClass1

Protected Sub mySub1
.....
End Sub

Protected Sub mySub2
.....
End Sub

End Class

---------------------
Public Class myClass2

Inherits myClass1

Sub newSub()
mySub1()
mySub2()
End Sub

End Class



ASP.NET : Public

Public is scope of the Method or the Sub / Function by the Public announced that the Sub / Function can run from external Class by new class or inherits Class.

Syntax
Public Class myClass1

Public Sub mySub1
.....
End Sub

Public Sub mySub2
.....
End Sub

End Class
---------------------
Public Class myClass2

Dim newClass As New myClass1

newClass.mySub1
newClass.mySub2

End Class



ASP.NET : Public Shared

Public Shared variables can be run from other Class without going through the New Class or Inherits Class

Syntax
Public Class myClass1

Public Shared Sub mySub1
.....
End Sub

Public Shared Sub mySub2
.....
End Sub

End Class
---------------------
Public Class myClass2

myClass1.mySub1()
myClass1.mySub2()

End Class



ASP.NET : Private

Private Sub / Class variables are defined, or make them available only it's Sub / Function, or Class but it can not be run from the others through the New Class, or any Inherits

Syntax
Public Class myClass1

Private Sub mySub1
.....
End Sub

Private Sub mySub2
.....
End Sub

Private Sub mySub3
mySub1()
mySub2()
End Sub

End Class



ASP.NET : Inherits

inheritance is a way to compartmentalize and reuse code by creating collections of attributes and behaviors called objects which can be based on previously created objects.

Syntax
Public Class myClass1

Protected Sub mySub1
.....
End Sub

Public Sub mySub2
.....
End Sub

End Class
---------------------
Public Class myClass2

Inherits myClass1

Sub newSub()
mySub1()
mySub2()
End Sub

End Class

End Asp.net Lesson 4.

ไม่มีความคิดเห็น:

แสดงความคิดเห็น