Office Excel在工作中应用非常广泛,尤其是数据处理优势不可倾慕。

Excel VBA究竟是什么?

VBA 是 Visual Basic语言(VB)内嵌在Office excel中的语言,V语言中最容易学懂的;应用广泛的办公软件;也是公认的最好的数据处理平台,作为程序的数据的输入、输出界面是最好不过了;在EXCEL中的计算成果数据非常方便进行二次处理,做资料什么的都很方便;为大家介绍一段VBA 计算方位角源码!

源码名称:chenchao_fwj(A,B,C,D,2)
源码格式:chenchao_fwj(测站X,测站Y,前视X,前视Y,显示格式)
当显示格式:等于-1为弧度,等于0为“DD MM SS”,等于1为“DD-MM-SS”,等于2为“DD°MMˊSS""”,等于其它值时返回十进制度值。
Function chenchao_fwj(Sx As Double, Sy As Double, Ex As Double, Ey As Double, abcyt As Integer)
Dim DltX As Double, DltY As Double, aa As Double, Pi As Double
Pi = Atn(1) * 4
DltX = Ex - Sx
DltY = Ey - Sy + 1E-20
aa = Pi * (1 - Sgn(DltY) / 2) - Atn(DltX / DltY)
aa = aa * 180 / Pi
chenchao_fwj = FFFsky(aa, abcyt)
End Function

Function FFFsky(Deg As Double, abcyt As Integer)
Dim tD As Integer, tM As Integer, tS As Double, tmp As Double
tD = Int(Deg)
tmp = (Deg - tD) * 60
tM = Int(tmp)
tmp = (tmp - tM) * 60
tS = Round(tmp, 1)
Select Case abcyt
Case -1
FFFsky = Deg * Atn(1) * 4 / 180
Case 0
FFFsky = tD & " " & Format(tM, "00") & " " & Format(tS, "00.0")
Case 1
FFFsky = tD & "-" & Format(tM, "00") & "-" & Format(tS, "00.0")
Case 2
FFFsky = tD & "°" & Format(tM, "00") & "ˊ" & Format(tS, "00.0") & """"
Case Else
FFFsky = Deg
End Select
End Function