Blog Lê Trung Hiếu

Just another WordPress.com site

Ôn tập tin thi học kì-4

Bài 8: Tọa độ cực


B1:Tạo 1 form (Add/Form),1 module (Add/Module)
B2:Code
Form code
Private Sub CmdThoat_Click()
Unload FrmToaDoCuc
End Sub
Private Sub CmdTinh_Click()
Dim Xtr As Double, Ytr As Double
Dim Xh As Double, Yh As Double
Dim Gock As Double, Sk As Double
Dim Xk As Double, Yk As Double
Xtr = Val(TxtXtr.Text)
Ytr = Val(TxtYtr.Text)
Xh = Val(TxtXh.Text)
Yh = Val(TxtYh.Text)
Gock = Val(TxtGocK.Text)
Sk = Val(TxtSk.Text)
ToaDoCuc Xtr, Ytr, Xh, Yh, Gock, Sk, Xk, Yk
TxtXk.Text = Format(Xk, “0.000”)
TxtYk.Text = Format(Yk, “0.000”)
End Sub
Module code
Public Sub ToaDoCuc(Xa As Double, Ya As Double, Xb As Double, Yb As Double, Gock As Double, Sk As Double, Xk As Double, Yk As Double)
Dim PVab As Double
PVab = TPV(Xa, Ya, Xb, Yb)
Gock = DomsRad(Gock)
Yk = Ya + Sk * Sin(PVab + Gock)
Xk = Xa + Sk * Cos(PVab + Gock)
End Sub
Public Function Pi() As Double
Pi = 4 * Atn(1)
End Function
Public Function TPV(Xa As Double, Ya As Double, Xb As Double, Yb As Double) As Double
Dim Dy As Double, Dx As Double, Anfa As Double
Dy = Yb – Ya
Dx = Xb – Xa
If Dx = 0 Then
If Dy > 0 Then
TPV = Pi() / 2
Else
TPV = 3 * Pi() / 2
End If
Else
Anfa = Atn(Dy / Dx)
If (Dx > 0) And (Dy > 0) Then TPV = Anfa
If (Dx 0) Then TPV = Pi() + Anfa
If (Dx 0) And (Dy < 0) Then
TPV = 2 * Pi + Anfa
End If
End Function
Public Function
DomsRad(goc As Double) As Double
Dim D As Integer, m As Integer, s As Integer
D = Fix(goc)
m = Fix((goc – D) * 100)
s = ((goc – D) * 100 – m) * 100
DomsRad = (D + m / 60 + s / 3600) * Pi() / 180
End Function

Bài 9: Tính Phương Vị

B1:Tạo 1 form (Add/Form),1 module (Add/Module)
B2:Code

Form code

Private Sub CmdThoat_Click()
Unload FrmTPV End Sub Private Sub CmdTinh_Click()
Dim Xa As Double, Ya As Double, Xb As Double, Yb As Double Dim PVab As Double
Xa = Val(TxtXa.Text)
Ya = Val(TxtYa.Text)
Xb = Val(TxtXb.Text)
Yb = Val(TxtYb.Text)
PVab = TPV(Xa, Ya, Xb, Yb)
TxtPV.Text = PVab
End Sub
Module code
Public Function Pi() As Double
Pi = 4 * Atn(1)
End Function
Public Function TPV(Xa As Double, Ya As Double, Xb As Double, Yb As Double) As Double
Dim Dy As Double, Dx As Double, Anfa As Double
Dy = Yb – Ya
Dx = Xb – Xa
If Dx = 0 Then
If Dy > 0 Then
TPV = Pi() / 2
Else
TPV = 3 * Pi() / 2
End If
Else
Anfa = Atn(Dy / Dx)
If (Dx > 0) And (Dy > 0) Then TPV = Anfa
If (Dx 0) Then TPV = Pi() + Anfa
If (Dx < 0) And (Dy < 0) Then TPV = Pi() + Anfa
If (Dx > 0) And (Dy < 0) Then TPV = 2 * Pi + Anfa End If End Function

Bài 10: Tách xâu (Bài này được gắn luôn vào menu chứ ko có form.)

B1:Tạo menu ( Ctrl + E) và 1 module (Add/Module)
Làm 1 cái submenu Tool (MnuTool) , menu con là TachXau (MnuToolTachXau)
B2:Code Private Sub MnuToolTachXau_Click()
Dim xau As String, kq() As String, dem As Long
xau = InputBox(“”, ” nhap vao 1 cau”)
dem = TachXau(xau, kq())
MsgBox dem MsgBox kq(1)
MsgBox kq(2)
MsgBox kq(dem)
End Sub
Module code

Public Function
TachXau(chuoi As String, kq() As String) As Long Dim k As Integer, dem As Long
Do
chuoi = Trim(chuoi)
dem = dem + 1
ReDim Preserve kq(1 To dem) As String

k = InStr(1, chuoi, ” “)
If k > 0 Then
kq(dem) = Mid(chuoi, 1, k – 1)
chuoi = Mid(chuoi, k)
Else
kq(dem) = chuoi
End If
Loop Until k = 0
TachXau = dem
End Function

Gửi phản hồi

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Log Out / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Log Out / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Log Out / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Log Out / Thay đổi )

Connecting to %s

%d bloggers like this: