Sunteți pe pagina 1din 147

7170

2 |

3 ......................... ................................ ................................
8 ..........................................................................
10 ..................... ................................................................
12 ...................................................... ................................
12 ......................................................
12 .....................................................................
12 ........... RAM(Random Access Memory)
13 ................................ Central Processing Unit
14 ........................................................................... Devices
14 .................................... ................................
16 ....................................... ................................
19 .................................................. ................................
20 ............. ................................ ................................
20 .......................................... Framework Class Library
21 ............................................... ................................ CLRMSIL
21 ....................... Automatic Garbage Collector
21 ..................................... Code Access Security
22 ............................................... Code Verification
22 ....................... ................................

3 |
23 .............................................. ................................
26 .. ................................................................
26 .................................................. ................................
27 ................................................. Solution Explorer
28 ............. ................................ Properties Window
28 ..................................................................... ToolBox
29 ................................................. ................................
30 .. ................................................................ Error List
31 ............................................................
36 ................................................ ................................Controls
36 ......................................... ................................ Properties
37 ................................................... ................................ Events
38 ......................................... ................................ Comments
38 ..................................................................... Variables
40 .............................................. ................................
41 .................................... ................................ Data Types
45 ............................................ ................................
46 ............................................... ................................ /
46 ............................. Arithmetic operators
47 ....................... String Concatenation operators

4 |
48 .............................................. Comparison operators
49 ....................................... Assignment Operators
50 ................................................... Logical operators
52 ......................... Short Circuited Operators
54 ..............................................................If
58 .............................................. Select Case
60 ...................................................... IIF
61 ....................................... ................................ Loops
62 ............................................... For Next
66 ............................................... Do..Loop
66 ........................................... Do..While
69 ............................................... ................................ While
69 ................................................. ................................While
69 ................................................ Do..Until
69 ................................ ................................ WhileUntil
71 .................................................. For EachNext
73 ...................................................... ................................ With
74 ................................................ ................................ Arrays
76 ................................. ................................
76 ....................................................
78 ................................ ................................
5 |
79 .....................................................................
85 ....................... ................................ Sorting Arrays
87 .......................................... ................................
89 ....................................... ................................
91 ..................................................................... Enumerations
98 ........................ ................................Handling Strings
98 .....................................................................
98 ...........................................................................
99 ............. ................................ ................................
100 ............................... ................................ SubString
102 ................................................................ Splitting
103 ............................................................. Concatening
105 ......................... ................................ Contains
108 ................................................................ Replace
108 ....................................... ................................Insert
109 ............................... ................................ Compare
110 ................... ................................................................ Format
112 ................................................. ................................
115 .......................................... ................................
123 ....................................... Functions and Procedures

6 |
132 .................................................. ................................
138 ........................................... Exceptions Handling
140 ............... Structured Exception Handling
144 .... Unstructured Exception Handling
147 ............................ ................................................................

7 |







8 |



1.0
2003

9 |


2015


Programming Program
Programming Languages


Operators Data Types Variables
Arrays Loops Conditions
String, Currency Exceptions Handling
and Date Handling
2015

10 |

Object Oriented Programming

11 |



Hardware
Software
Hardware

:RAM(Random Access Memory)

12 |

Addressing
Address

:Central Processing Unit

13 |



:Devices

Input devices

Output Devices

Storage Devices

10

14 |

Binary Language
1 0



10



( )
Binary encoding 1 0
) Decimal encoding
: ( 9 0
.

15 |



Programming Program
Language



Binary Machine Code Machine Language
Language


InterepterCompiler

16 |
VB.Net
VB.Net

F# C++C#VB.Net
Basic
1963 VB.Net
VB.Net


ASP.Net

High-Level Programming Language VB.Net


17 |
2


Low Level Languages

High Level Languages

VB.Net
Visual Basic 1.019901963
Visual
Basic 6

18 |
Microsoft VB.Net
2015 Visual Studio

2015

http://www.microsoft.com/en-us/download/details.aspx?id=44934

http://download.microsoft.com/download/4/A/0/4A0D63BC -0F59-45E3-A0FF-
9019285B3BC5/vs2015.preview_ult_ENU.iso

19 |



Framework Class Library




Windows Forms
Web Forms Graphical User Interfaces (GUI)
asp.net


Framework Class
Library

20 |
CLRMSIL
ILMicrosoft Intermediate LanguageMSIL
Common CIL Intermediate Language
Intermediate Language
Compiling
Runtime
Just-In-Time CompilerJIT

CLR
Common Language Runtime
CLR

:Automatic Garbage Collector

Objects CLR

CLR
Garbage Collector

Code Access Security

CLR CAS

21 |
CLR

Code Verification

CLR

Handling Exceptions

IL JIT CLR

CLR

Framework Class LibraryCLR

22 |

Start
Visual Studio

23 |
4

New File
Project

24 |

( ) 6

Visual Basic
First Windows Forms Application
Program

OK

25 |


File
Edit

26 |
Project

:Solution Explorer 2





View
Ctrl+Alt+L

Solution Explorer 9

27 |
:Properties Window 3



Events
Properties Window View
F4

Properties Window 10

:ToolBox 4

28 |
Ctrl+Alt+X View

ToolBox 11

: 5

29 |
Form Design 12

:Error List 6

Error List 13

30 |

Button
All Windows Forms Common Controls

14

15

31 |

Properties Window
TextF4

16

32 |
Form1 Class

Public Class Form1

Classes

Method
Click

Private Sub Button1_Click(sender As Object, e As


EventArgs) Handles Button1.Click

End Sub

33 |
Events Methods

End Sub

MsgBox(")"

MsgBox

StartF5

34 |

35 |
Controls
Form
ListBox Button Textbox

.Toolbox

Properties



F4


Control

36 |


.

Events

Click
Procedure

37 |

Comments
Compiler
Documentation


'

'

'
'
'

Variables

38 |

Screen


Variables
Runtime

39 |



Runtime
Dim

Dim VARIABLE_NAME As DATA_TYPE

Dim
AS VARIABLE_NAME

Dim myNumber As Integer '


Dim myDouble As Double '
Dim myChar As Char '
Dim myString As String '
Dim myDateTime As DateTime '

40 |
Dim myBool As Boolean '

Dim myNumber1, myNumber2, myNumber3 As Integer


Data Types

String Integer
Common
Language Runtime (CLR)

41 |

Floating-PointInteger

Integer

Byte
32 -32 768Short2550
Floating-Point 767

Double

Dim IntegerNumber As Integer


Dim ByteNumber As Byte
Dim SByteNumber As SByte
Dim ShortNumber As Short
Dim LongNumber As Long
Dim SingleNumber As Single
Dim UIntegerNumber As UInteger
Dim ULongNumber As ULong
Dim UShortNumber As UShort

42 |
:1

ULong UInteger U
Unsigned LongUnsigned Integer

Unsigned

Unsigned

32,767 - 32,768 Short


Unsigned

65,5350UShort

:2

Int32 Int16
Int64
IntegerInt32

43 |

Short Int16
Integer Int32
Long Int64
String
Char


. False True 2 Boolean
255 0 1 Byte
127 -128 1 SByte
Unicode Symbol 2 Char
9999 31 0001 1 8 Date
16 Decimal
8 Double
2,147,483,647 -2,147,483,648 4 Integer
4,294,967,295 0 4 UInteger
-9,223,372,036,854,775,808 8 Long
9,223,372,036,854,775,807
18,446,744,073,709,551,615 0 8 ULong
Object 4 Object
32,767 - 32,768 2 Short
65,535 0 2 UShort
-3.4028235E38 4 Single
3.4028235E38
Unicode Character 2 0 2 String

44 |

Dim myNumber1 As Integer = 156


Dim myNumber2 As Integer
myNumber2 = 245

156 myNumber1
myNumber2

Dim Name As String = ""


Dim Religion As String
Religion = ""

Dim Number1 As Integer = 540


Dim Number2 As Integer
Number2 = Number1


45 |

Dim Number1 As Integer = 540


Dim Number2 As Integer = Number1

Number2 Number1
540

Arithmetic operators


+
-
*
/
\
46 |
Mod
^

Dim FirstNumber As Integer = 20

Dim SecondNumber As Integer = 4


'
Dim Sum As Integer = FirstNumber + SecondNumber

'
Dim Dif As Integer = FirstNumber - SecondNumber

'
Dim Mul As Integer = FirstNumber * SecondNumber

'
Dim Div As Integer = FirstNumber / SecondNumber

'
Dim IntDiv As Integer = FirstNumber \ SecondNumber

'
Dim Modulus As Integer = FirstNumber Mod SecondNumber

'
Dim Exp As Integer = FirstNumber ^ SecondNumber

String Concatenation operators

&

47 |
Dim FirstString As String = "Think First "
Dim SecondString As String = "Code Later"
Dim ResultString As String = FirstString & SecondString
'
Dim ResultString As String = FirstString + SecondString

ResultString
Think First Code Later

Comparison operators


boolean
false true


>
<
=
<>
>=
<=

'5 4
Dim Value1 As Boolean = 4 > 5

'5 4
Dim Value2 As Boolean = 4 < 5
48 |
'5 4
Dim Value3 As Boolean = 4 = 5

'5 4
Dim Value4 As Boolean = 4 <> 5

'5
Dim Value5 As Boolean = 4 <= 5

'5 4
Dim Value6 As Boolean = 4 >= 5

Assignment Operators


=
^=
*=
/=
\=
+=
-=
&=

49 |


' 5
myVariable = 5

25 2 5 2
myVariable ^= 2

'50 2 25 2
myVariable *= 2

'25 2 50 2
myVariable /= 2

'12 2 25 2
myVariable \= 2

'14 2+12 2
myVariable += 2

'12 2 14 2
myVariable -= 2

'127 7 12 7
myVariable &= 7

Logical operators

False True Boolean


AND

50 |
OR

'
Dim Value1 As Boolean = (3 < 4 And 7 > 5) 'Value1 = True

'( 8 5)
Dim Value2 As Boolean = (10 > 9 And 5 = 8) 'Value2 =
False

'
Dim Value3 As Boolean = (8 < 4 Or 6 > 2) 'Value3 = True

'
Dim Value4 As Boolean = (1 > 9 Or 6 = 3) 'Value4 = False

'

Dim Value5 As Boolean = (1 > 9 Or 6 / 2 = 3) 'Value5 =
True

51 |
Short Circuited Operators


AND
False

False
ANDTrue

AndAlso
AND

OR
True True
False
OR
True True

True

52 |
OrElse
True

OrElseAndAlso

'Value1 = False
Dim Value1 As Boolean = (3 > 4 AndAlso 7 > 5 AndAlso 8
> 4)

'Value2 = True
Dim Value2 As Boolean = (5 > 9 OrElse 4 = 2 * 2 OrElse
6 < 4)

False Value1
AndAlso False

4TrueValue2
OrElse True 2 * 2
True

53 |
If



Messenger Skype

Condition
Flow Control

If ' Then
'
ElseIf ' Then
'
Else
'
End If

If
ElseIf

Else

54 |

Windows
Forms Application


txtUserName TextBox
txtPassWord TextBox
lblUserName Label

lblPassWord Label

btnOK Button

55 |
btnCancel BuTTon

btnOK


Private Sub btnOK_Click(sender As Object, e As EventArgs)


Handles btnOK.Click

Dim UserName As String = "myUserName"


Dim PassWord As String = "myPWD123"

If txtUserName.Text = UserName And txtPassWord.Text =


PassWord Then
MsgBox(")"
ElseIf txtUserName.Text <> UserName And
txtPassWord.Text = PassWord Then
MsgBox(")"
ElseIf txtUserName.Text = UserName And txtPassWord.Text
<> PassWord Then
MsgBox(")"
Else
MsgBox(")"
End If
End Sub

PassWord UserName
myPWD123myUserName

56 |


Else

57 |
Select Case
Select Case
If
If

Select Case '


Case '
'
Case '
'
Case '
'
Case Else '
'
End Select

Select Case
Case

Case Else

58 |


txtNumber TextBox
lblNumber Label
btnOK Button
ClickbtnOK

Private Sub btnOK_Click(sender As Object, e As EventArgs)


Handles btnOK.Click

'
Dim PlanetCount As Integer = 9

'
Dim PlanetCountEnterred As Integer =
Val(txtNumber.Text)

Select Case PlanetCountEnterred


Case 9
MsgBox(")"
Case Is < 8
MsgBox(")"
Case 10 To 70
MsgBox(")"
Case 8
59 |
MsgBox(")"
Case Else
MsgBox(")"
End Select
End Sub

IIF
IIF
Ternary Operator

IIf(, , )

IIF

Dim Password As String = "myPWD123"


Dim Access_State As String = IIf(Password = "myPWD123",
"" , ")"

Access_State
myPWD123 Password
myPWD123 Password
Access_State

60 |
Loops

61 |
For Next

For..Next

For Count = Start To End [Step Step]


'[statements]
[Exit For]
Next Count

Count
EndStart

Step
Exit For
Next

Windows Forms Application



lbNumbers ListBox
btnRepeat Button
For..Next

62 |

Click btnRepeat

Private Sub btnRepeat_Click(sender As Object, e As


EventArgs) Handles btnRepeat.Click
'
Dim nCount As Integer

For nCount = 0 To 10 Step 1


Me.lbNumbers.Items.Add(": " & nCount)
Next

End Sub

Count
100
LbNumbers

63 |

1 Step

Step

Dim nCount As Integer

For nCount = 0 To 10 Step 2


Me.lbNumbers.Items.Add(": " & nCount)
Next

64 |

Dim nCount As Integer

For nCount = 27 To 0 Step -3


Me.lbNumbers.Items.Add(": " & nCount)
Next

65 |
Do..Loop

Do..Loop

: Do..While

While
True

Do
'
Loop While '


Windows Forms Application

66 |

lblNumber Label
txtNumber TextBox
btnCalculate Button

lbDetails ListBox

btnCalculateClick

Private Sub btnCheck_Click(sender As Object, e As


EventArgs) Handles btnCalculate.Click

Dim Number As Integer = Val(txtNumber.Text)


Dim Counter As Integer = 0
Do
lbDetails.Items.Add(Number & " * " & Counter & "
= " & Number * Counter)
Counter += 1
Loop While Counter <= 10

End Sub

Number
Val txtNumber
0 Counter
Number
Counter
10

67 |
10 0
8

Do While

Dim Number As Integer = Val(txtNumber.Text)


Dim Counter As Integer = 0
Do While Counter <= 10
lbDetails.Items.Add(Number & " * " & Counter & "
= " & Number * Counter)
Counter += 1
Loop

While
Loop While

68 |
:While
Do While 1 = 3
MsgBox(")"
Loop

1 While
While

:While
Do
MsgBox(")"
Loop While 1 = 3

While

Do..Until

Do..While

UntilDo

:While Until
While Until

True
False


WhileUntil
69 |
Private Sub btnCheck_Click(sender As Object, e As
EventArgs) Handles btnCalculate.Click

Dim Number As Integer = Val(txtNumber.Text)


Dim Counter As Integer = 0
Do Until Counter = 10
lbDetails.Items.Add(Number & " * " & Counter & "
= " & Number * Counter)
Counter += 1
Loop

End Sub

10
10 Counter

70

70 |
While
Do Until
Loop

Do Until 1 = 3
MsgBox(")"
Loop

Do
MsgBox(")"
Loop Until 1 = 3

For EachNext

For Each Item As DATA_TYPE In GROUP


'
Next Item



71 |
Windows Forms Application


lblName Label
txtName TextBox
btnSplit Button
lbDetails ListBox

Click btnSplit

Private Sub btnSplit_Click(sender As Object, e As


EventArgs) Handles btnSplit.Click

Dim FullName As String = txtFullName.Text

72 |
For Each chr As Char In FullName
Me.lbDetails.Items.Add(chr)
Next

End Sub

FullName
For EachtxtFullName

ListBox

With

Object With

Button1.Text = ""
Button1.BackColor = Color.Blue
Button1.Size = New Point(100, 40)
Button1.ForeColor = Color. Yellow
Button1.TextAlign = ContentAlignment.MiddleCenter
Button1.Focus()

With Button1

With Button1
.Text = ""

73 |
.BackColor = Color.Blue
.Size = New Point(100, 40)
.ForeColor = Color.Yellow
.Focus()
.TextAlign = ContentAlignment.MiddleCenter
End With

Arrays


Dim Value1, Value2, Value3, Value4, Value5, Value6,


Value7, Value8, Value9, Value10 As Double

74 |

Arrays

Value

Index

75 |
Index

one-dimensional
array



Double

Dim Marks(9) As Double

76 |
Dim Marks() As Double = {20, 19, 14, 17, 13, 11.5,
16.25, 18.75, 9, 15}

10


20 0
19 1
14 2
17 3
13 4
11.5 5
16.25 6
18.75 7
9 8
15 9

Dim Marks(9) As Double

Marks(0) = 20
Marks(1) = 19
Marks(2) = 14
Marks(3) = 17
Marks(4) = 13
Marks(5) = 11.5
Marks(6) = 16.25
Marks(7) = 18.75
Marks(8) = 9
Marks(9) = 15

77 |

Length

Dim Marks() As Double = {20, 19, 14, 17, 13, 11.5,


16.25, 18.75, 9, 15}
MsgBox(Marks.Length)


10

Count

Dim Marks() As Double = {20, 19, 14, 17, 13, 11.5,


16.25, 18.75, 9, 15}

MsgBox(Marks.Count)

78 |

Dim Marks() As Double = {20, 19, 14, 17, 13, 11.5,


16.25, 18.75, 9, 15}

Dim Value As Double = Marks(2)

MsgBox(Marks(8))

Dim Sum As Double = Marks(1) + Marks(4)



Average
ListBox

Windows Forms Application


79 |

lblArray Label
txtArray TextBox
btnAvg Button
lbDetails ListBox
ClickbtnAvg

Private Sub btnAvg_Click(sender As Object, e As


EventArgs) Handles btnAvg.Click

Dim ItemCount As Integer = Val(txtArray.Text)

Dim intArray(ItemCount) As Integer

Dim Rand As New Random

Dim Sum As Integer = 0

For Count As Integer = 0 To intArray.Length - 1

intArray(Count) = Rand.Next(100)

lbDetails.Items.Add(intArray(Count))

Sum += intArray(Count)
Next

Dim Average As Double = Sum / intArray.Length

MsgBox(": & " Average)

End Sub

80 |
Dim ItemCount As Integer = Val(txtArray.Text)

ItemCount

Dim intArray(ItemCount) As Integer

intArray

Dim Rand As New Random

Rand

Dim Sum As Integer = 0

Sum

For Count As Integer = 0 To intArray.Length 1

81 |

intArray(Count) = Rand.Next(10)

100
RandomRandNext

lbDetails.Items.Add(intArray(Count))

ListBox
lbDetails

Sum += intArray(Count)

Dim Average As Double = Sum / intArray.Length

MsgBox(": & " Average)

82 |
10

83 |
Dim WeekArray(6) As String

WeekArray(0) = ""
WeekArray(1) = ""
WeekArray(2) = ""
WeekArray(3) = ""
WeekArray(4) = ""
WeekArray(5) = ""
WeekArray(6) = ""

For Each Day As String In WeekArray


lbDetails.Items.Add(": " & Day & " :" &
Day.Length & " . ")
Next

84 |
Sorting Arrays



ArraySort

Dim NamesArray(4) As String

NamesArray(0) = ""
NamesArray(1) = ""
NamesArray(2) = ""
NamesArray(3) = ""
NamesArray(4) = ""

Array.Sort(NamesArray)

Me.lbDetails.Items.AddRange(NamesArray)

ListBoxAddRange
Add

85 |

Dim NumbersArray() As Integer = {8, 6, 1, 9, 12, 3}

Array.Sort(NumbersArray)

For Count As Integer = 0 To NumbersArray.Count - 1


Me.lbDetails.Items.Add(NumbersArray(Count))
Next

86 |


Array Sort

ArrayReverse

Dim myArray() As Integer = {4, 2, 3, 1}

'
Me.lbDetails.Items.Add(")"
For Each Item As Integer In myArray
Me.lbDetails.Items.Add(Item)
Next

'
Array.Sort(myArray)
Me.lbDetails.Items.Add(")"
For Each Item As Integer In myArray
Me.lbDetails.Items.Add(Item)

87 |
Next

'
Array.Reverse(myArray)
Me.lbDetails.Items.Add(")"
For Each Item As Integer In myArray
Me.lbDetails.Items.Add(Item)
Next

88 |

Dim TwoDimArray(2, 5) As Integer

Dim TwoDimArray(0 To 2, 0 To 5) As Integer

6 3
183*6

(0,0) (0,1) (0,2) (0,3) (0,4) (0,5)


(1,0) (1,1) (1,2) (1,3) (1,4) (1,5)
(2,0) (2,1) (2,2) (2,3) (2,4) (2,5)

Dim TwoDimArray(2, 5) As Integer

TwoDimArray(0, 3) = 23

TwoDimArray(1, 4) = 195

TwoDimArray(2, 1) = 56

89 |

'
Dim myArray(1, 2) As Integer

'
myArray(0, 0) = 7
myArray(0, 1) = 2
myArray(0, 2) = 5

'
myArray(1, 0) = 3
myArray(1, 1) = 8
myArray(1, 2) = 6

'
Dim row, col As Integer

'
For row = 0 To 1
'
For col = 0 To 2
lbDetails.Items.Add(myArray(row, col))
Next
Next

myArray


90 |
Enumerations



Constants

91 |
Windows Forms Application


lblColor Label
cmbColor ComboBox
Enumerations
View Code

92 |

Public Class Form1

Enum EnumColors
Red
Blue
Green
Purple
Orange
End Enum

End Class

EnumColors

93 |

0 Red
1 Blue
2 Green
3 Purple
4 Orange

Enum EnumColors
Red = 4
Blue = 2
Green = 1
Purple = 3
Orange = 0
End Enum

cmbColor
Form_Load

Dim ArrayColors() As String = {"Red",


"Blue",
"Green",
"Purple",
"Orange"}

94 |
Me.cmbColor.Items.AddRange(ArrayColors)

cmbColor ComboBox
SelectedIndexChanged

Select Case cmbColor.SelectedIndex


Case EnumColors.Red
Me.BackColor = Color.Red
Case EnumColors.Blue
Me.BackColor = Color.Blue
Case EnumColors.Green
Me.BackColor = Color.Green
Case EnumColors.Purple
Me.BackColor = Color.Purple
Case EnumColors.Orange
Me.BackColor = Color.Orange
End Select


EnumColors

95 |


Enumerations

Public Class Form1

Enum EnumColors
Red
Blue
Green
Purple
Orange
End Enum

Private Sub Form1_Load(sender As Object, e As EventArgs)


Handles MyBase.Load

Dim ArrayColors() As String = {"Red",


"Blue",
"Green",
"Purple",
"Orange"}

Me.cmbColor.Items.AddRange(ArrayColors)

End Sub
96 |
Private Sub cmbColor_SelectedIndexChanged(sender As
Object, e As EventArgs) Handles cmbColor.SelectedIndexChanged
Select Case cmbColor.SelectedIndex
Case EnumColors.Red
Me.BackColor = Color.Red
Case EnumColors.Blue
Me.BackColor = Color.Blue
Case EnumColors.Green
Me.BackColor = Color.Green
Case EnumColors.Purple
Me.BackColor = Color.Purple
Case EnumColors.Orange
Me.BackColor = Color.Orange
End Select
End Sub

End Class

97 |
Handling Strings


LenLength

Dim Name As String = "Khalid"


MsgBox(Name.Length)
'
MsgBox(Len(Name))

UCase
ToUpper

98 |
Dim Name As String = "khalid"
MsgBox(Name.ToUpper())
'
MsgBox(UCase(Name))

ToUpper UCase
KHALIDkhalid

LCase UCase
ToUpper
ToLower

Dim Name As String = "KHALID"


MsgBox(Name.ToLower())
'
MsgBox(LCase(Name))

99 |
SubString

MidString Substring Mid


Mid(string_Name, start_Index, Length)

string_Name

start_Index
01

Length

Mid

Dim Name As String = "KHALID"

Dim strResult1 As String = Mid(Name, 1, 3)

Dim strResult2 As String = Mid(Name, 2, 4)

100 |
KHALID strResult1
KHA 3
strResult2
HALI4KHALID

String SubString

String_Name.Substring(start_Index, Length)

String_Name
MID 0 Start_Index
1

Dim Name As String = "KHALID"

Dim strResult1 As String = Name.Substring(0, 3)

Dim strResult2 As String = Name.Substring(2, 4)


KHAstrResult1

101 |

40 SubString
ALIDstrResult2

Splitting

String Split


Split

Dim Names As String = "Khalid-Hamid-Nihad-Hussain"

Dim ArrayNames() As String = Names.Split("-")

MsgBox(ArrayNames(0)) 'display Khalid


MsgBox(ArrayNames(1)) 'display Hamid
MsgBox(ArrayNames(2)) 'display Nihad
MsgBox(ArrayNames(3)) 'display Hussain

Split

102 |
Concatening

&

Dim First_Name As String = "Khalid"


Dim Last_Name As String = " ESSAADANI"

Dim FullName As String

FullName = First_Name + Last_Name


'Or
FullName = First_Name & Last_Name

FullName
Khalid ESSAADANILast_NameFirst_Name

String Concat

Dim First_Name As String = "Khalid"


Dim Last_Name As String = " ESSAADANI"

Dim FullName As String

FullName = String.Concat(First_Name, Last_Name)

103 |
Last_Name First_Name FullName
Concat

Join

Dim First_Name As String = "Khalid"


Dim Last_Name As String = "ESSAADANI"

Dim FullName As String

FullName = String.Join(" ", First_Name, Last_Name)

Space

StringJoin

Dim Expression1 As String = ""


Dim Expression2 As String = ""

Dim Expression3 As String = String.Join(" " ,


Expression1, Expression2)

MsgBox(Expression3)

104 |
Contains

Contains
False True
Contains
String

Dim strText As String = ""

If strText.Contains(" = )"True Then


MsgBox(")"
Else
MsgBox(" )"
End If

strText Contains
TrueContains

105 |

IndexOf

1IndexOf

Dim strText As String = "Think First, Code Later"

If strText.IndexOf("Think") > -1 Then


MsgBox("Word is Found at Index: " &
strText.IndexOf("Think"))
Else
MsgBox("Not Found :(")
End If

IndexOf strText Think

106 |
Think

IndexOf
1

Dim strText As String = "Think First, Code Later"

If strText.IndexOf("Manage") = -1 Then
MsgBox("Not Found :(")
Else
MsgBox("Word is Found at Index: " &
strText.IndexOf("Think"))
End If

IndexOf Manage
1

107 |
Replace

Replace

Dim FalseText As String = ""

Dim TrueText As String = FalseText.Replace("",


")"

MsgBox(TrueText)


Replace

TrueText

Insert


Insert

Dim Expression As String = ""

Dim FinalExpression As String = Expression.Insert(0,


")"

108 |
MsgBox(FinalExpression)


0
FinalExpression

Compare


Compare
0 CompareTo
1

Dim First_String As String = "Khalid"

Dim Second_String As String = "Hussain"

Dim Result As Integer

Result = String.Compare(First_String, Second_String)

If Result = 0 Then
MsgBox(")"

109 |
Else
MsgBox(")"
End If
'
Result = First_String.CompareTo(Second_String)

If Result = 0 Then
MsgBox(")"
Else
MsgBox(")"
End If

Format

String Format

Format

Dim First_Name As String = "Khalid"


Dim Last_Name As String = "ESSAADANI"
Dim FullName As String
FullName = String.Format("My name is: {0} {1}",
First_Name, Last_Name)
MsgBox(FullName)

Format

110 |
Format

Dim Name As String = "Hamid MAKBOUL"


Dim Age As Byte = 25
Dim Country As String = "Morocco"
Dim City As String = "Beni Mellal"

MsgBox(String.Format("Informations About Customer:


- Name: {0}
- Age: {1}
- Country: {2}
- City: {3}", Name, Age,
Country, City))


Format

111 |

Format
c
Currency

Dim Price As Double = 78651.75


MsgBox(String.Format("The price is: {0:c}", Price))


Format

Dim Name As String = "TV"


Dim Model As String = "Philips"
Dim Quantity As Short = 125
Dim Amount As Double = 1375.25
MsgBox(String.Format("Product Informations:
- Name: {0}

112 |
- Model: {1}
- Qty: {2}
- Amount: {3:c}", Name,
Model, Quantity, Amount))


Amount





Format#

Dim Amount As Double = 45612.658


MsgBox(String.Format("{0:### ###.##}", Amount))

113 |

Dim Amount As Double = 45612.658


MsgBox(String.Format("{0:###,###.#}", Amount))


0 #

114 |
Dim Amount As Double = 45612.5
MsgBox(String.Format("{0:000 000.00}", Amount))


Format

Dated

Now()

Dim CurrentDate As Date = Now


MsgBox(String.Format("{0:d}", CurrentDate))

115 |
CurrentDate
Format Date
d

Dim CurrentDate As Date = Now

'
MsgBox(String.Format("{0:d}", CurrentDate))

'
MsgBox(String.Format("{0:dd/MM}", CurrentDate))

'
MsgBox(String.Format("{0:dd}", CurrentDate))

'
MsgBox(String.Format("{0:MM/yyyy}", CurrentDate))

116 |
'
MsgBox(String.Format("{0:yyyy}", CurrentDate))

'
MsgBox(String.Format("{0:yyyy/MM/dd}", CurrentDate))

'
MsgBox(String.Format("{0:ss:mm:hh - yyyy/MM/dd}",
CurrentDate))

'
MsgBox(String.Format("{0:ss}", CurrentDate))

'
MsgBox(String.Format("{0:mm}", CurrentDate))

'
MsgBox(String.Format("{0:hh}", CurrentDate))

'
MsgBox(String.Format("{0:ss:mm:hh}", CurrentDate))

'
MsgBox(String.Format("{0:mm:hh}", CurrentDate))

'
MsgBox(String.Format("{0:d}", CurrentDate))

117 |

'
MsgBox(String.Format("{0:dd/MM}", CurrentDate))

'
MsgBox(String.Format("{0:dd}", CurrentDate))

118 |

'
MsgBox(String.Format("{0:MM/yyyy}", CurrentDate))

'
MsgBox(String.Format("{0:yyyy}", CurrentDate))

'
MsgBox(String.Format("{0:yyyy/MM/dd}", CurrentDate))

119 |

'
MsgBox(String.Format("{0:ss:mm:hh - yyyy/MM/dd}",
CurrentDate))

'
MsgBox(String.Format("{0:ss}", CurrentDate))

120 |

'
MsgBox(String.Format("{0:mm}", CurrentDate))

'
MsgBox(String.Format("{0:hh}", CurrentDate))

121 |

'
MsgBox(String.Format("{0:ss:mm:hh}", CurrentDate))

'
MsgBox(String.Format("{0:mm:hh}", CurrentDate))

122 |
Functions and Procedures

Function Procedure


Sub

Sub Procedure_Name(ByVal Param1 As Data_Type, ByRef


Param2 As Data,....)
'do that
End Sub

ByRefByVal

123 |

Windows Forms Application



lblName Label
txtName TextBox
btnShow Button
Public Class Form1

Sub ShowMessage(ByVal Name As String)


MsgBox(String.Concat(" :" ,
Name))
End Sub

124 |
Name ShowMessage

Click
btnShow

ShowMessage
txtName

Private Sub btnShow_Click(sender As Object, e As


EventArgs) Handles btnShow.Click

ShowMessage(txtName.Text)

End Sub

ShowMessage Name

125 |
btnShow

Public Class Form1


Sub ShowMessage(ByVal Name As String)
MsgBox(String.Concat(" :" ,
Name))
End Sub

Private Sub btnShow_Click(sender As Object, e As


EventArgs) Handles btnShow.Click
ShowMessage(txtName.Text)
End Sub
End Class

126 |
Functions

Function

Windows Forms Application



lblNumber1 Label
lblNumber2 Label
lblChoose Label

txtNumber1 TextBox
txtNumber2 TextBox
rbAdd RadiButton
rbSubs RadiButton
rbMul RadiButton
127 |
rbDiv RadiButton
btnCalculate Button

Function Calculate(ByVal Number1 As Double, ByVal Number2


As Double) As Double

Dim Result As Double

If rbAdd.Checked = True Then


Result = Number1 + Number2
ElseIf rbSubs.Checked = True
Result = Number1 - Number2
ElseIf rbMul.Checked = True
Result = Number1 * Number2
ElseIf rbDiv.Checked = True
Result = Number1 / Number2
End If
Return Result

End Function

Function Calculate
Double

Double Result

128 |
Number2Number1

Result

btnCalculateClick

Number2 Number1 Calculate


Private Sub btnCalcul_Click(sender As Object, e As


EventArgs) Handles btnCalcul.Click

Dim N1, N2, Result As Double

N1 = Val(txtNumber1.Text)
N2 = Val(txtNumber2.Text)

Result = Calculate(N1, N2)

MsgBox(String.Format("The Result Is: {0}", Result))


End Sub

N1
N2 txtNumber1
Result txtNumber2
Calcuate

129 |

Private Sub btnCalcul_Click(sender As Object, e As


EventArgs) Handles btnCalcul.Click

MsgBox(String.Format("The Result Is: {0}",


Calculate(Val(txtNumber1.Text), Val(txtNumber2.Text))))

End Sub

130 |

131 |


ByRef ByVal

By Value

Copy

By Reference

Number
2

Sub CalcByVal(ByVal Number As Integer)


Number *= 2
MsgBox(": " & Number)
End Sub

132 |
502 25Number


By Referenece

Sub CalcByRef(ByRef Number As Integer)


Number *= 2
MsgBox(": " & Number)
End Sub

Click

Dim Number As Integer = 16

'
MsgBox(" : " & Number)

'
CalcByVal(Number)

'
MsgBox(" & " Number)

'
CalcByRef(Number)

'
MsgBox(" : " & Number)

133 |

Dim Number As Integer = 16

16 Number
16

'
MsgBox(" : " & Number)

16

'
CalcByVal(Number)

Number CalcByVal
16
16 * 2 16 Number
32

134 |

'
MsgBox(" & " Number)

16

16

'
CalcByRef(Number)


Number
Number 16 32 16 * 2 CalcByRef
.32

'
MsgBox(" : " & Number)

32
3216

135 |

By Value

136 |
By Reference

137 |
Exceptions Handling
Runtime

Windows Forms Application


lblAge Label
txtAge TextBox
btnShow Button

*
2
btnShow

138 |
Private Sub btnShow_Click(sender As Object, e As
EventArgs) Handles btnShow.Click

Dim Age As Integer = txtAge.Text

MsgBox(" : " & Age * 2)

End Sub

Age
Invalid Cast

139 |
Invalid Cast Exception

Structured Exception Handling

TryCatchFinally

Try
'
Catch ex As Exception
'
Finally
'
End Try

Try
Catch

140 |
Finally

TryCatch
CatchTry

Try

Dim Age As Integer = txtAge.Text

MsgBox(" : " & Age * 2)

Catch ex As Exception

MsgBox(")"

txtAge.Clear()

txtAge.Focus()

Finally

MsgBox(")"

End Try

Try

141 |
Dim Age As Integer = txtAge.Text

MsgBox(" : " & Age * 2)

Catch ex As Exception

MsgBox(")"

txtAge.Clear()

txtAge.Focus()

Exception ex


Exception InvalidCastException
Focus

Finally

MsgBox(")"

End Try

142 |

Finally

Catch

143 |
Unstructured Exception Handling


On Error

'
On Error GoTo Label

Label: '

'
On Error Resume Next

'
On Error GoTo Label

Label

On Error GoTo ErrorMessage

Dim Age As Integer = txtAge.Text

MsgBox(" : " & Age * 2)

ErrorMessage:

MsgBox(")"

144 |
On Error
ErrorMessage

ErrorMessage
GoTo Label
GoTo

On Error Resume Next


On Error Resume Next

Dim Age As Integer = txtAge.Text

MsgBox(" : " & Age * 2)

145 |

146 |


2015


Object Oriented Programming

mobarmijoun@gmail.com
how2progspace@gmail.com

www.mobarmjoun.com

www.youtube.com/EssaadaniTV
www.facebook.com/EssaadaniPage

147 |

S-ar putea să vă placă și