You are on page 1of 48

www.kompongsom4u.blogspot.

com

VB.NET

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

VB.NET





Download Free

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

. VB.NET

VB.NET

VB.NET

. Double Click Icon Setup


. Install Visual Studio 2008

. Run File

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

. Button Next

. I have read and Accept the License Term > Next

. Full > Button Install

Tel : 070 908 739

www.kompongsom4u.blogspot.com
.

VB.NET

> Next > Finish

. VB.NET
. Start Button
. All Program ( windows 7 ) > Microsoft Visual Studio 2008

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

. Project
. Visual Studio 2008
. File ( Ctrl + N ) > New Project

-Name : Project
. Windows Forms Application > Click OK

. Project
. File manu
. Save Form / Save All

. Save Project > OK

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

. Interface VB.NET

Form

Solution
Explorer

Property
Toolbox

-Form : Interface Design Graphic


-Toolbox :

Design Form

-Property : Toolbox
-Solution Explorer : Project

. Form Run

Form


. Project Menu
. Windows Application Property

Startup Form

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

.
Form


. ( )

.
. File Menu
. Exit

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

. Toolbox


Toolbox

Visual Studio 2008 Toolbox Toolbox


-textbox

-button

-Label

-Combo box

-Checkbox

Toolbox

-Button

Button

-Label

Form

-Combo box

( Male or Female )

-Textbox

-List box


List box

-Radio Button

Radio Button

-Timer

-ListView


Database

-DateTimePicker

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

. Solution Explorer
Solution Explorer Project Form Module
Project Project Form

10

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

. Property Object
Property Object Toolbox
Button
Property Toolbox

Property Textbox

Property
-Name : Textbox
-BackColor : Textbox
-ForeColor : Textbox
-Font :

Textbox

11

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

HTML , JAVA VB.NET

Keyword ViablieName As Data_Type

Ex.

Dim

Keyword ViablieName1, ViablieName1 As Data_Type

Ex.

Dim

-Keyword

as

string

str ,

as

string

:
(Public , Static , Dim ,

-Viable Name
-As

str

Private )
:

: Data_type

-Data_Type :

Ex.
-Public a as integer
-Dim a as string
-private k as long
General Declaration Static Variable

.. ( Scope Of Variable )

(Life

time Variable )
-Global Variable

-Global Friend Variable

-Module Level Variable

-Dynamic local Variable


-Static Local Variable

12

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

... Global Variable


Global Variable

- Standard Module ( Code )


- Keyword Public

- Scope Form
Project
- Life Time : Application
-Ex. Public a as integer

... Global Friend Variable


Global Friend Variable
- Standard Module ( Code )
- Keyword Friend

- Scope Form
Project
- Life Time : Application
-Ex. Friend ak as String

... Module Level Variable


Module Level Variable

- Standard Module , Form Module ,Class Module


- Keyword Private / Dim

- Scope Module
- Life Time : Application
-Ex. Dim/Private c as String

... Dynamic Local Variable


Dynamic Local Variable

-
Procedure ( Sub Procedure , Function Procedure)
- Keyword Dim

- Scope Procedure
- Life Time : Application
-Ex. Dim c as String

13

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

... Static Local Variable


Static Local Variable

-
Procedure ( Sub Procedure , Function Procedure)
- Keyword Static

- Scope Procedure
- Life Time : Application
-Ex. Static c as String

..


- Keyword ( dim , Private , Static ,...)
- (223)

- Under Score ( a ad a_ad )


- (&($#)
- Keyword

As Data_type

. ( Data_Type )
..


..

VB.net , HTML ...

Byte

8-bit

0 Through 255

Short

16-bit

-32,768 to 32,768

Integer

32-bit

-2,147,483,648 to 2,147,483,648

Single

32-bit

-3,4028235E38 to 3,4028235E38

Long

64-bit

-9,223,372,036,854,775,808 to 9,223,372,036,854,775,808

Double

64-bit

-1,7976931348621E308 to 1,7976931348621E308

Char

16-bit

any Unicode symbol in the range

Boolean

16-bit

true or False

14

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

. Byte , Integer , Long

. Single, Double

15

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Code :

16

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Code :

17

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Code :

18

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Code :

19

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Control Structure

Statement Statement Program


VB.NET Control Structure

. if Statement

. if else Statement

. if else_if Statement
. Select Case Statement

.. IF STATEMENT

Expression (Expression ) Statement


Expression ( Expression ) Statement 2 if Statement


Syntax

20

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

.. IF ESLE STATEMENT
If else Statement If Statement

Expression1 Statement1
if Statement

Syntax

Else

Expression1 Statement 2

21

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

if else Statement

22

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

.. IF ESLE-IF STATEMENT

if else_if Statement : if-else statement


( )

if-else-if Statement

23

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Code :
Private Sub bntPayroll_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bntPayroll.Click
Dim MonH, TueH, WedH, ThuH, FriH, SatH, SunH, OT As Integer
Dim HourlyRate, TotalPay As Single
HourlyRate = Val(txtHR.Text)
MonH = Val(txtMon.Text)
TueH = Val(txtTue.Text)
WedH = Val(txtWed.Text)
ThuH = Val(txtThu.Text)
FriH = Val(txtFri.Text)
SatH = Val(txtSat.Text)
SunH = Val(txtSun.Text)
OT = 0
If MonH > 8 Then
OT = OT + (MonH - 8)
MonH = 8
End If
If TueH > 8 Then
OT = OT + (TueH - 8)
TueH = 8
End If
If WedH > 8 Then
OT = OT + (WedH - 8)
WedH = 8
End If
If ThuH > 8 Then
OT = OT + (ThuH - 8)
ThuH = 8
End If
If FriH > 8 Then
OT = OT + (FriH - 8)
FriH = 8
End If
OT = OT + SatH + SunH
TotalPay = (MonH + TueH + WedH + ThuH + FriH) * HourlyRate + (2 *
HourlyRate * OT)
txtOTH.Text = OT & "Hours"
txtTP.Text = Format(TotalPay, "$#,##0.00")
End Sub

24

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

.. SELECT CASE STATEMENT


Select Case If else , if else if Statement

Select Case

25

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Select Case

Select Case

. - Need to work harder
. - Average

. - Above Average
. - Good

. - Excellence

26

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

.
Repeat Statement Block Statement

Loop C Loop
. While Loop Statement

. do_while Loop Statement


. For Loop Statement
Loop

Instruction

Computer

Control Variable

.. .While Loop Statement

While Loop Expression Statement While Loop

( Execute ) Expression Statement


Block Statement Execute Expression
while Loop

Statement

27

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

.. Do While Loop Statement

do While Loop

Execute Statement
Loop

Expression Expression Statement


Expression

Execute

Textbox

28

Tel : 070 908 739

www.kompongsom4u.blogspot.com

.. For Loop Statement

For loop

Loop

VB.NET

29

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Textbox

.. Goto Statement


Statement
Loop

Code

30

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

+ DoEvents() Function
-

eRbIedIm,IeGaytMeNIrkarGnuvtn Current process pakmYyryHeBlxIxNHeBl Runtime


edIm,Ipl;karRtYtBiniteTA O.S .
bnab;BItMeNIrkarenaHva)anplk; arRtYtBiniteTA Current Process vij.
kareRbIR)as; Do Events KWedIm,I Delay Process rbs; Loop .

Private Sub bntDoEvents_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles bntDoEvents.Click
Dim i, a As Integer
Call Randomize()
Do
lblNumber.Text =012 & Int(Rnd() * 1000000)
For i = 1 To 3000
Application.DoEvents()
Next
a = a + 1
Loop Until a > 500
End Sub

31

Tel : 070 908 739

Array

www.kompongsom4u.blogspot.com

VB.NET


Index

Array Location Memory Index Array


VB.net
LBound ( Lower Bound ) index

UBound ( Upper Bound ) Index

-LBound : index Array


-UBound : index

Array

VB.net Array Fix Size Array

Dynamic Array

. One Dimensional Array


.. Fix Size Array
Fix Size Array Array

Location Runtime

. Fix Size Array

Ex. Dim MyArray(5) as integer


Array
-Lbound

Array = 0

-Ubound

Array = 5

Array Index

32

Array

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

33

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET


Array
-Listbox

-Textbox Array
-Button Start

-Button Stop

34

Tel : 070 908 739

VB.NET

Dynamic Array Array

Location Runtime

www.kompongsom4u.blogspot.com

.. Dynamic Array

. Dynamic Array

Ex. Dim DynamiceArray() as Integer


Dynamic Array
Runtime Keyword
Redim Procedure Array

Ex. Dim A() as Integer


ReDim A(3)

enaHeK)an
A(0)=2
A(1)=4
A(2)=10
A(3)=30

Array

Code Array

35

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Dim mArray() As Integer


'Dim test() As Integer = {1, 3, 5, 6, 7}
Private Sub FrmDynamicArray_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
Me.Show()
txtAdd.Text = ""
txtDisplay.Text = ""
txtAdd.Focus()
ReDim mArray(0)
End Sub
Private Sub bntAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bntAdd.Click
Dim m As Integer
m = Val(txtAdd.Text)
If m <> 0 Then
mArray(UBound(mArray)) = m
ReDim Preserve mArray(UBound(mArray) + 1)
End If
txtAdd.SelectionStart = 0
txtAdd.SelectionLength = Len(txtAdd.Text)
txtAdd.Focus()
End Sub
Private Sub bntShow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bntShow.Click
Dim i As Integer
Dim Str As String
For i = LBound(mArray) To UBound(mArray) - 1
Str = Str & "Array(" & i & ")=" & mArray(i) & vbCrLf
Next
txtDisplay.Text = Str
End Sub
Private Sub bntExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bntExit.Click
End
End Sub

36

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

. Two Dimensional Array


Two Dimensional Array Array Row Colum
.. Fix Size Array

Ex: Dim mArray(2,3) As Integer


Dim B(4,5) As Long
Dim Str(2,5) As String

Dim A(3,4) As Integer


A
0
1
2
3

0
A(0,0)
A(1,0)
A(2,0)
A(3,0)

enaHeKtagtaragdUcxageRkam

1
A(0,1)
A(1,1)
A(2,1)
A(3,1)

2
A(0,2)
A(1,2)
A(2,2)
A(3,2)

3
A(0,3)
A(1,3)
A(2,3)
A(3,3)

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

Code

37

Array

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Dim mArray( 1, 2) As Integer


Private Sub FrmTwoDimensionalArray_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim x As Integer, y As Integer
Call Randomize()
For x = LBound(mArray, 1) To UBound(mArray, 1)
For y = LBound(mArray, 2) To UBound(mArray, 2)
mArray(x, y) = 10 + Int(89 * Rnd())
Call lstValues.Items.Add(mArray(x, y))
Next
Next
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub bntDisplay_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles bntDisplay.Click
Try
Dim row As Integer, col As Integer
Dim temp As String
temp = "
Col0 Col1 Col2"
Call lstDisplay.Items.Add(Space(6) & temp)
For row = LBound(mArray, 1) To UBound(mArray, 1)
temp = "Row" & row & " "
For col = LBound(mArray, 2) To UBound(mArray, 2)
temp = temp & Space(3) & mArray(row, col) & " "
Next
Call lstDisplay.Items.Add(temp)
Next
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub bntExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bntExit.Click
End
End Sub

.. Dynamic Array
-

Ex:

eRbI ReDim nig ReDim Preserve edIm,IRbkas ArrayeLIgvij .


kMenIn Index RbRBWte TAcMeBaH Dynamic Two-Dimentional Array )anEt Index
cugeRkayEtbu:eNaH .

Dim A() As Intger


- ReDim A(2,3)

enaHeKTTYl)an

LBound(A,1)=0
LBound(A,2)=0
UBound(A,1)=2
UBound(A,2)=3

38

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Code

39

Array

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Public Class adddynamic_array


Dim mArray(,) As String = New String(20, 4) {}
Dim i As Integer
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnadd.Click
Try
mArray(i, 0) = txtname.Text
mArray(i, 1) = txtstudy.Text
mArray(i, 2) = txtclass.Text
If RSMale.Checked = True Then
mArray(i, 3) = "M"
Else
mArray(i, 3) = "F"
End If
mArray(i, 4) = txtfield.Text
i = i + 1
Call cleardata()
Catch ex As Exception
End Try
End Sub
Sub cleardata()
txtname.Text = ""
txtstudy.Text = ""
txtclass.Text = ""
txtfield.Text = ""
RSFemal.Checked = False
RSMale.Checked = False
txtname.Focus()
End Sub
Private Sub btnshow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnshow.Click
Try
If i < 0 Then
MsgBox("Benning recode", MsgBoxStyle.Exclamation, "Recode")
End If
txtname.Text = mArray(i - 1, 0)
txtstudy.Text = mArray(i - 1, 1)
txtclass.Text = mArray(i - 1, 2)
If mArray(i - 1, 3) = "M" Then
RSMale.Checked = True
Else
RSFemal.Checked = True
End If
txtfield.Text = mArray(i - 1, 4)
i = i - 1
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub txtfield_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtfield.TextChanged
End Sub
End Class

40

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Procedure Standard Module Public ( Call

Project ) VB.NET Procedure

- Sub Procedure (Sub Program)


- Function Procedure
. Sub Procedure


Function

.. Sub Procedure

41

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

42

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Keyboard

Private Sub CmdMin_Click()


Dim val1 As Long, val2 As Long, val3 As Long
val1 = txtVal1.Text
val2 = txtVal2.Text
val3 = txtVal3.Text
Call Minimum(val1, val2, val3)
End Sub
Private Sub Minimum(min As Long, x As Long, y As Long)
If x < min Then
min = x
End If
If y < min Then
min = y
End If
lblMin.Caption = "Min Valus is=" & min
End Sub
. Function Procedure

Function Procedure Sub Procedure

.. FunctionProcedure

43

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Function Mention(Avg As Single) As String


Select Case Avg
Case Is > 100
Mention = "Invalid"
Case Is >= 95
Mention = "Excellent"
Case Is >= 85
Mention = "VeryGood"
Case Is >= 75
Mention = "Good"
Case Is >= 65
Mention = "Fair"
Case Is >= 50
Mention = "Medium"
Case Else
Mention = "Weak"
End Select
End Function
Private Sub CmdOK_Click()
Dim Men As Single
Men = Val(txtAvg.Text)
txtMention = Mention(Men)
End Sub

44

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

eyIgGacbegtI RbePTGefredayxneyIg)anenAkg Visual Basic edayeRbI Structure keyword.


beckeTsenHKWvamansarsMxan;. ]TahrNdUcCaGkcg;begIt record type sMrab;rkSaTinyenAkg Files
b kGkcg;eGayTinyEdlman Type epSgKamksitenAeRkam Type EtmYyenaHeyIgRtUvbegIt (Structure) .
edIm,IbegIt Structure , GkRtUvEteRbI Structure keyword . enHKWCarebobbegIt Structure :
.

KWCaeQaHn (Structure) . EdleKarBtam smtki meQaHGefr .


- Datamember: KWCaeQaHrbs;Fatun (Structure) . EdleKarBtamsmtikmeQaHGefr .
- Structure: mineRbICa)a:ra:Em:Rt b Return type rbs; Sub Program or Function )aneLIy .
edIm,IeRbI Properties b Data member rbs;eQaH Structure eKRtUvbegItbRbkasGefrneQaHStructure.
-

VarName :

45

Tel : 070 908 739

www.kompongsom4u.blogspot.com

46

VB.NET

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

Database Network

Database Database
Microsoft Access , MySQL Server 2008

. Database MySQL Server 2008

MySQL Server 2008

MySQL Sever 2008 Local Machine



MySQL Server 2008
Windows Sever

.. Database MySQL Server 2008


Local Machine
Module


Form Load
Imports System.Data.SqlClient
Public Class Form1
Private MyConnect As SqlConnection
Private MyCommand As SqlCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
MyConnection = New SqlConnection("Server=KOMPONGSOM4UPC;Database=student;User id=sa;password=1234")
MyConnection.Open()
''txtid.Text = AutoNum()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class

47

Tel : 070 908 739

www.kompongsom4u.blogspot.com

VB.NET

.. Database MySQL Server 2008


Window Server
Module


Form Load
Imports System.Data.SqlClient
Public Class Form1
Private MyConnect As SqlConnection
Private MyCommand As SqlCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
MyConnection = New SqlConnection("Server=IP Server;Database=student;User
id=sa;password=1234")
MyConnection.Open()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class

. Database Microsoft Access


Database Microsoft Access MySQL Server

Access
Imports System.Data
Imports System.Data.OleDb

Public Class Form1


Dim con As OleDbConnection
Dim cmd As OleDbCommand
Dim ad As OleDbDataAdapter
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
con = New OleDbConnection("provider=microsoft.ace.oledb.12.0;data
source=F:\\HMS.accdb")
ad = New OleDbDataAdapter("select * from Jeneralnurses", con)
End Sub
End Class

48

Tel : 070 908 739

You might also like