Bài 1: Nạp danh sách
Bài 2: Thực hiện phép tính
Bài 3: Giải phương trình bậc 2
Bài 4: Giải hệ phương trình
BÀi 5: Danh sách
Bài 6: Quản lý nhân sự
Bài 7: menu
Bài 8: Máy tính
Private Sub cmdchon_Click()
Dim i
Do While i <= list1.ListCount - 1
If list1.Selected(i) = True Then
list2.AddItem list1.List(i)
list1.RemoveItem i
Else
i = i + 1
End If
Loop
End Sub
Private Sub cmdchontat_Click()
Dim i
For i = 0 To list1.ListCount - 1
list2.AddItem list1.List(i)
Next i
list1.Clear
End Sub
Private Sub cmdchuyen_Click()
Dim i
For i = 1 To list2.ListCount - 1
list1.AddItem list2.List(i)
Next i
list2.Clear
End Sub
Private Sub cmdnap_Click()
Dim filename, filenumber, antem
filename = "c:\tuan.txt"
filenumber = FreeFile
anitem = ""
Open filename For Input As filenumber
Do While Not EOF(filenumber)
Line Input #filenumber, antem
list1.AddItem antem
Loop
End Sub
Private Sub cmdxoa_Click()
Dim i
Do While i <= list1.ListCount - 1
If list1.Selected(i) = True Then
list1.RemoveItem i
Else
i = i + 1
End If
Loop
End Sub
Bài 2: Thực hiện phép tính
Private Sub cmddong_Click()
End
End Sub
Private Sub cmdthulai_Click()
txt1.Text = ""
txt2.Text = ""
txt1.SetFocus
End Sub
Private Sub cmdtinh_Click()
If optcong.Value Then
MsgBox "Cong hai so"
txtketqua.Text = CInt(txt1.Text) + CInt(txt2.Text)
ElseIf opttru.Value Then
MsgBox "Tru hai so"
txtketqua.Text = CInt(txt1.Text) - CInt(txt2.Text)
ElseIf optnhan.Value Then
MsgBox "Nhan hai so"
txtketqua.Text = CInt(txt1.Text) * CInt(txt2.Text)
ElseIf optcongchuoi.Value Then
txtketqua.Text = txt1.Text & txt2.Text
End If
End Sub
Bài 3: Giải phương trình bậc 2
Private Sub cmdgiai_Click()
Dim a, b, c, delta
a = CInt(txta.Text)
b = CInt(txtb.Text)
c = CInt(txtc.Text)
delta = b ^ 2 - 4 * a * c
If (delta = 0) Then
MsgBox "Phuong trinh co nghiem kep"
ElseIf (delta < 0) Then
MsgBox "Phuong trinh vo nghiem"
Else
MsgBox "Phuong trinh co 2 nghiem phan biet"
txtx1.Text = (-b + Sqr(delta)) / (2 * a)
txtx2.Text = (-b - Sqr(delta)) / (2 * a)
End If
End Sub
Bài 4: Giải hệ phương trình
Private Sub cmdgiai_Click()
Dim a1, a2, b1, b2, c1, c2, d, dx, dy
a1 = CInt(txta1.Text)
a2 = CInt(txta2.Text)
b1 = CInt(txtb1.Text)
b2 = CInt(txtb2.Text)
c1 = CInt(txtc1.Text)
c2 = CInt(txtc2.Text)
d = a1 * b2 - a2 * b1
dx = c1 * b2 - c2 * b1
dy = a1 * c2 - a2 * c1
If (dx <> 0) Then
MsgBox "Phuong trinh co nghiem"
txtx.Text = dx / d
txty.Text = dy / d
ElseIf (dx = 0 And dy = 0 And d = 0) Then
MsgBox "Phuong trinh vo dinh"
ElseIf (dx = 0 And dy = 0) Then
MsgBox "Phuong trinh vo nghiem"
End If
End Sub
BÀi 5: Danh sách
Private Sub cmdluu_Click()
Dim i, filename, filenumber
filename = "c:\phuong.txt"
filenumber = FreeFile
Open filename For Output As filenumber
For i = 0 To List1.ListCount - 1
Print #filenumber, List1.List(i)
Next i
Close filenumber
End Sub
Private Sub cmdthem_Click()
List1.AddItem txthoten.Text & ";" & txtnamsinh.Text & ";" & txtquequan.Text
End Sub
Private Sub cmdtiep_Click()
txthoten.Text = ""
txtnamsinh.Text = ""
txtquequan.Text = ""
txthoten.SetFocus
End Sub
Private Sub cmdxoa_Click()
Dim i
Do While i <= List1.ListCount - 1
If List1.Selected(i) = True Then
List1.RemoveItem i
Else
i = i + 1
End If
Loop
End Sub
Bài 6: Quản lý nhân sự
Private Sub cmdPrevious_Click()
Adodc1.Recordset.MovePrevious
End Sub
Private Sub cmdfirst_Click()
Adodc1.Recordset.MoveFirst
End Sub
Private Sub cmdnext_Click()
Adodc1.Recordset.MoveNext
End Sub
Private Sub cmdlast_Click()
Adodc1.Recordset.MoveLast
End Sub
Private Sub cmdthem_Click()
Adodc1.Recordset.AddNew
txthoten.SetFocus
End Sub
Private Sub cmdcapnhat_Click()
Adodc1.Recordset.Update
End Sub
Private Sub cmdsuadoi_Click()
txthoten.Locked = False
txtngaysinh.Locked = False
txtlop.Locked = False
txtquequan.Locked = False
txtnghe.Locked = False
End Sub
Private Sub cmdxoa_Click()
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
End Sub
Bài 7: menu
Private Sub mnuchudo_Click()
Text1.ForeColor = vbRed
End Sub
Private Sub mnuchuxanh_Click()
Text1.ForeColor = vbBlue
End Sub
Private Sub mnuhien_Click()
Text1.Visible = True
End Sub
Private Sub mnunenden_Click()
Text1.BackColor = vbBlack
End Sub
Private Sub mnunenvang_Click()
Text1.BackColor = vbYellow
End Sub
Private Sub mnutat_Click()
Text1.Visible = False
End Sub
Bài 8: Máy tính
Private Sub cmdchia_Click()
txtketqua.Text = CInt(txtso1.Text) / CInt(txtso2.Text)
End Sub
Private Sub cmdcong_Click()
txtketqua.Text = CInt(txtso1.Text) + CInt(txtso2.Text)
End Sub
Private Sub cmdnhan_Click()
txtketqua.Text = CInt(txtso1.Text) * CInt(txtso2.Text)
End Sub
Private Sub cmdtru_Click()
txtketqua.Text = CInt(txtso1.Text) - CInt(txtso2.Text)
End Sub