blackjack > 14-03-12, 01:24 PM
hoanglonglangtu > 14-03-12, 03:13 PM
blackjack > 14-03-12, 03:14 PM
hoanglonglangtu > 14-03-12, 06:26 PM
Private Sub Command1_Click()
DoCmd.SetWarnings False
DoCmd.RunCommand "delete * from MaTran"
Dim n As Integer
Dim m As Integer
Dim a(1 To 10, 1 To 10) As Single
Dim i As Integer
Dim j As Integer
n = InputBox("Nhap so hang n:")
m = InputBox("Nhap so cot m:")
For i = 1 To n
For j = 1 To m
a(i, j) = InputBox("Nhap vao gia tri a[" & i & "," & j & "]")
DoCmd.RunCommand "Insert into MaTran values ('" & i & "," & j & "'," & a(i,j) & ")"
Next
Next
End Sub
- Kế tiếp : nút tính toán ( command2)
Private Sub Command2_Click()
Dim max, min As Single
Dim db As Database
Dim Rs As Recordset
Set Rs = db.OpenRecordset("MaTran", DB_OPEN_TABLE)
Rs.MoveFirst
max = Rs!DuLieu
vtmax = Rs!vitri
min = Rs!DuLieu
vtmin = Rs!vitri
While Rs.EOF = False
If Rs!SoLieu < min Then
min = Rs!SoLieu
vtmin = Rs!vitri
End If
If Rs!SoLieu > max Then
max = Rs!SoLieu
vtmax = Rs!vitri
End If
Rs.MoveNext
Loop
Rs.Close
MsgBox " da tinh xong"
textbox1= " so max = " & max & " o vi tri " & vtmax & " so nho nhat " & min & " o vi tri " & vtmin
end sub
- Nút hiển thị kết quả : command 3 chỉ cần hiển thị kqua
Private Sub Command3_Click()
MsgBox "ket qua " & chr(10) & textbox1
End Sub
blackjack > 14-03-12, 08:33 PM
hoanglonglangtu > 15-03-12, 08:12 AM
Option Compare Database
Public Sub Command1_Click()
DoCmd.SetWarnings False
DoCmd.RunSQL "delete * from MaTran"
Dim n As Integer
Dim m As Integer
Dim a(1 To 10, 1 To 10) As Single
Dim i As Integer
Dim j As Integer
n = InputBox("Nhap so hang n:")
m = InputBox("Nhap so cot m:")
For i = 1 To n
For j = 1 To m
a(i, j) = InputBox("Nhap vao gia tri a[" & i & "," & j & "]")
DoCmd.RunSQL "Insert into MaTran values ('" & i & ", " & j & " '," & a(i, j) & ")"
Next
Next
End Sub
Public Sub Command2_Click()
Dim min, max, vtmax, vtmin
Dim Db As Database
Set Db = CurrentDb()
Dim Rs As Recordset
Set Rs = Db.OpenRecordset("MaTran", DB_OPEN_TABLE)
Rs.MoveFirst
min = Rs!solieu
max = Rs!solieu
vtmax = Rs!viTri
vtmin = Rs!viTri
Do While Rs.EOF = False
If min > Rs!solieu Then
min = Rs!solieu
vtmin = Rs!viTri
End If
If max < Rs!solieu Then
max = Rs!solieu
vtmax = Rs!viTri
End If
Rs.MoveNext
Loop
Rs.Close
MsgBox " Da tinh xong "
Me.Text4 = "So lon nhat : " & max & " o vi tri " & vtmax & " so nho nhat : " & min & " o vi tri " & vtmin
Exit Sub
End Sub
Private Sub Command3_Click()
MsgBox "ket qua " & Chr(10) & Me.Text4
End Sub