14. 2
2.1 Visual Basic
BASIC Thomas Kurtz
Interpreter
GW-BASIC Interpreter
DOS
Sub Program
User Defind QUICK BASIC Visual Basic
15. QUICK
BASIC PDS BASIC Microsoft
BASIC Visual Basic
Visual Basic
Windows Visual
GUI : Graphic
User Interface) BASIC Beginner All-
Purpose Symbolic Instruction Code ) Visual
Basic VB Visaul Basic.net VB.NET)
Microsoft Visual Studio .NET)
Windows Operating System)
Dotnet Framework)
UML = Unified Modeling
Language) Visual Studio .NET)
IDE = Integrated Development Environment)
SQL Server) Visaul Basic.net VB.NET)
VC#) VJ#) VC++)
ASP .NET)
16. CLR = Common Language
Runtime)
Visual Basic Programming
Language)
Windows 95/98
Windows NT
Basic
Beginner’s All Purpose Symbolic Instruction
“ ” Basic
C).
Pascal) Fortian) Assembler)
Basic
MBASIC (Microsoft Basic). BASICA (Basic
Advanced): GWBASIC QuickBasic
Ms DOS
QBASIC
Text Mode
Windows
Windows
DOS
Text Mode
27. dialog box 5
windows application
Windwos FormsApplication
Name: WindowsApplication1
MyFirstProgram
OK IDE Visual
Basic 6 Form common
controls toolbox, Solution explorer properties
29. calcuate source
code
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim num1, num2, sum As Single
num1 = 100
num2 = 200
sum = num1 + num2
MsgBox(" The Sum of " & num1 & " and " & num2 & " is "
& sum)
End Sub
42. idcar Text 255
brand Text 255
gen Text 255
bortyear Text 255
price Number Integer
detailcar Text 255
num Number Integer
3 1.2
43. Idrent1 Text 255
Id Text 255
name Text 255
add Text 255
Tel Text 255
Idcar Text 255
Brand Text 255
Gen Text 255
bortyear Text 255
Price Number Integer
detailcar1 Text 255
amount Number Integer
pledeg Number Integer
Night Date/Time Long Date
status1 Text 255
3 1.3
44. Idreat Text 255
Idcar Text 255
Id Text 255
Amount Number Integer
Night Date/Time Long Date
3 1.4
51. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Enabled = True
If TextBox1.Text = "" Then
MessageBox.Show(" ")
Exit Sub
End If
If ComboBox1.Text = " " Then
sql = "select * from customer where id='" & TextBox1.Text & "'"
With rs
.CommandType = CommandType.Text
.CommandText = sql
.Connection = conn
dr = .ExecuteReader
End With
dr.Read()
If dr.HasRows Then
TextBox2.Text = dr.Item("id")
TextBox3.Text = dr.Item("name1")
TextBox4.Text = dr.Item("add1")
TextBox5.Text = dr.Item("tel")
Else
MessageBox.Show(" ")
Call Button5_Click(Nothing, Nothing)
End If
dr.Close()
Else
sql = "select * from customer where name1 like'%" &
TextBox1.Text & "%'"
With rs
.CommandType = CommandType.Text
.CommandText = sql
.Connection = conn
dr = .ExecuteReader
End With
dr.Read()
If dr.HasRows Then
TextBox2.Text = dr.Item("id")
TextBox3.Text = dr.Item("name1")
TextBox4.Text = dr.Item("add1")
TextBox5.Text = dr.Item("tel")
Else
MessageBox.Show(" ")
Call Button5_Click(Nothing, Nothing)
End If
dr.Close()
End If
End Sub
53. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = ""
Or TextBox5.Text = "" Then
MessageBox.Show(" ")
Exit Sub
End If
sql = "insert into customer(id,name1,add1,tel) values('" &
TextBox2.Text & "','" & TextBox3.Text & "' , '" & TextBox4.Text & "', '" &
TextBox5.Text & "')"
With rs
.CommandText = sql
.Connection = conn
.ExecuteNonQuery()
End With
MessageBox.Show(" ", " ")
Call Button5_Click(Nothing, Nothing)
End Sub
57. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
If MessageBox.Show(" ", " OH CAR",
MessageBoxButtons.YesNo, MessageBoxIcon.Error) = MsgBoxResult.Yes Then
sql = "delete * from customer where id='" & TextBox1.Text & "'"
With rs
.CommandText = sql
.ExecuteNonQuery()
End With
MessageBox.Show(" ", " ")
Call Button5_Click(Nothing, Nothing)
Else
Exit Sub
End If
End Sub
59. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
End Sub
62. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If TextBox3.Text = "" Then
MessageBox.Show(" ")
Exit Sub
End If
sql = "select * from car where idcar='" & TextBox3.Text & "'"
With rs
.CommandType = CommandType.Text
.CommandText = sql
.Connection = conn
dr = .ExecuteReader
End With
dr.Read()
If dr.HasRows Then
TextBox1.Text = dr.Item("idcar")
ComboBox5.Text = dr.Item("brand")
ComboBox1.Text = dr.Item("gen")
ComboBox2.Text = dr.Item("bortyear")
TextBox5.Text = dr.Item("price")
TextBox2.Text = dr.Item("detailcar")
TextBox4.Text = dr.Item("num")
Else
MessageBox.Show(" ")
End If
dr.Close()
End Sub
71. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If TextBox3.Text = "" Then
MessageBox.Show(" ")
Exit Sub
End If
Sql = "select * from car where idcar='" & TextBox3.Text & "'"
With rs
.CommandType = CommandType.Text
.CommandText = Sql
.Connection = conn
dr = .ExecuteReader
End With
dr.Read()
If dr.HasRows Then
TextBox1.ReadOnly = True
TextBox1.Text = dr.Item("idcar")
ComboBox5.Text = dr.Item("brand")
ComboBox1.Text = dr.Item("gen")
ComboBox2.Text = dr.Item("bortyear")
ComboBox4.Text = dr.Item("price")
TextBox2.Text = dr.Item("detailcar")
Else
MessageBox.Show(" ")
End If
dr.Close()
End Sub
73. Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button7.Click
If TextBox12.Text = "" Then
MessageBox.Show(" ")
Exit Sub
End If
sql = "select * from car where idcar='" & TextBox12.Text & "'"
With rs
.CommandType = CommandType.Text
.CommandText = sql
.Connection = conn
dr = .ExecuteReader
End With
dr.Read()
If dr.HasRows Then
TextBox11.Text = dr.Item("idcar")
ComboBox5.Text = dr.Item("brand")
ComboBox1.Text = dr.Item("gen")
ComboBox2.Text = dr.Item("bortyear")
TextBox13.Text = dr.Item("price")
TextBox2.Text = dr.Item("detailcar")
tmp = dr.Item("num")
Else
MessageBox.Show(" ")
End If
dr.Close()
End Sub
75. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
If TextBox7.Text = "" Or ComboBox5.Text = "" Or ComboBox1.Text = ""
Or ComboBox2.Text = "" Or TextBox13.Text = "" Or TextBox11.Text = "" Or
TextBox6.Text = "" Or TextBox5.Text = "" Or TextBox4.Text = "" Or
TextBox3.Text = "" Or TextBox2.Text = "" Then
MessageBox.Show(" ")
Exit Sub
End If
sql = "insert into
rent1(idrent,id,name1,add1,tel,idcar,brand,gen,bortyear,price,detailcar1,am
ount,pledeg,night,status1)"
sql &= "values('" & TextBox7.Text & "','" & TextBox3.Text & "','" &
TextBox4.Text & "',"
sql &= "'" & TextBox5.Text & " ','" & TextBox6.Text & "','" &
TextBox11.Text & "',"
sql &= "'" & ComboBox5.Text & "', '" & ComboBox1.Text & "','" &
ComboBox2.Text & "',"
sql &= "'" & CInt(TextBox13.Text) & "','" & TextBox2.Text & "','" &
CInt(TextBox10.Text) & "',"
sql &= "'" & CInt(TextBox9.Text) & "','" &
DateTimePicker1.Value.ToLongDateString & "','1')"
76. With rs
.CommandText = sql
.Connection = conn
.ExecuteNonQuery()
End With
tmp = 0
sql = "update car set num='" & tmp & "' where idcar='" &
TextBox12.Text & "'"
With rs
.CommandText = sql
.Connection = conn
.ExecuteNonQuery()
End With
MessageBox.Show(" ", " ")
Call Button3_Click(Nothing, Nothing)
End Sub
Fowchart
77. No
Yes
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
ComboBox1.Text = ""
ComboBox2.Text = ""
ComboBox4.Text = ""
ComboBox5.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
80. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox2.Enabled = False
TextBox3.Enabled = False
TextBox4.Enabled = False
TextBox5.Enabled = False
If TextBox1.Text = "" Then
MsgBox(" ", MsgBoxStyle.Critical, " ")
Exit Sub
End If
sql = " select
rent1.id,rent1.idcar,rent1.amount,rent1.night,car.num from rent1,car where
rent1.idrent='" & TextBox1.Text & "'"
sql &= " and rent1.status1='1'"
sql &= " and rent1.idcar=car.idcar"
With rs
.CommandType = CommandType.Text
.CommandText = sql
.Connection = conn
dr = .ExecuteReader
End With
dr.Read()
If dr.HasRows Then
81. TextBox2.Text = dr.Item("id")
TextBox3.Text = dr.Item("idcar")
TextBox4.Text = dr.Item("amount")
TextBox5.Text = dr.Item("night")
tmp = dr.Item("num")
Else
MsgBox(" ", MsgBoxStyle.Exclamation,
" ")
End If
dr.Close()
End Sub
Fowchart
82. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
If TextBox1.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = ""
Or TextBox8.Text = "" Then
MsgBox(" ")
Exit Sub
End If
sql = " update rent1 set status1='0'"
sql &= "where idrent = '" & TextBox1.Text & "'"
With rs
.Connection = conn
.CommandText = sql
.ExecuteNonQuery()
End With
tmp = CInt(TextBox4.Text) + tmp
sql = "Update car set num='" & tmp & "'"
sql &= " where idcar='" & TextBox3.Text & "'"
With rs
.Connection = conn
.CommandText = sql
.ExecuteNonQuery()
End With
sql = "insert into returns(idreat,idcar,id,amount,night)"
sql &= " values('" & TextBox1.Text & "','" & TextBox3.Text & "','"
& TextBox2.Text & "',"
83. sql &= "'" & CInt(TextBox4.Text) & "','" & TextBox5.Text & "')"
With rs
.CommandText = sql
.Connection = conn
.ExecuteNonQuery()
End With
MsgBox(" ")
Call Button4_Click(Nothing, Nothing)
End Sub
Fowchart
No
84. Yes
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
End Sub