EXCEL-VBA自定义角度转换函数

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

'1、角度转换函数
'1.1---“度分秒”化“度”函数
'注:“度分秒”->“度”的角度单位转化
Public Function 度分秒_度(C2 As Double)
Dim FuHao As Integer, C1 As Double
Dim Du As Integer, Fen As Integer, Miao As Double
FuHao = Sgn(C2)
C1 = C2 + 0.0000000000001 * FuHao
C1 = Abs(C1)
Du = Int(C1)
Fen = Int(C1 * 100) - Int(C1) * 100
Miao = (C1 * 100 - Int(C1 * 100)) * 100
If Fen >= 60 Or Miao >= 60 Then
度分秒_度 = "输入有误!"
Exit Function
End If
度分秒_度 = FuHao * (Du + Fen / 60 + Miao / 3600) End Function
'1.2---“度.分秒”化“弧”函数
Public Function 度分秒_弧(度分秒 As Double) As Double
Dim FuHao As Integer, C1 As Double
Dim 度 As Integer, 分 As Integer, 秒 As Double
FuHao = Sgn(度分秒)
C1 = 度分秒 + 0.0000000000001 * FuHao
C1 = Abs(C1)
度 = Int(C1)
分 = Int(C1 * 100) - Int(C1) * 100
秒 = (C1 * 100 - Int(C1 * 100)) * 100
If 分 >= 60 And 秒 >= 60 Then
度分秒_弧= "“分秒”输入有误!"
Exit Function
End If
If 分 >= 60 Then
度分秒_弧= "“分”输入有误!"
Exit Function
End If
If 秒 >= 60 Then
度分秒_弧= "“秒”输入有误!"
Exit Function
End If
度分秒_弧 = FuHao * (度 + 分 / 60 + 秒 / 3600) * 3.14159265358979 / 180 End Function
'1.4---“度”化“度分秒”函数
'“度”转化为“度。

分’秒"”格式
Public Function 度化度分秒(C2 As Double, Miao_Jingdu As Integer) As String
Dim FuHao As Integer, C1 As Double
Dim Du As Double, Miao As Double
FuHao = Sgn(C2)
C1 = C2 + 0.0000000000001 * FuHao
C1 = Abs(C1)
Du = Int(C1)
Fen = Int((C1 - Int(C1)) * 60)
Miao = Round(((C1 - Int(C1)) * 60 - Int((C1 - Int(C1)) * 60)) * 60, Miao_Jingdu)
If Miao > 59.9999 Then
Miao = 0
Fen = Fen + 1
If Fen = 60 Then
Du = Du + 1
Fen = 0
End If
End If
度化度分秒= FuHao * Du & "°" & Fo rmat(Fen, "00" + Application.WorksheetFunction.Rept("0", 0)) & "′" & _
Fo rmat(Miao, "00." + Application.WorksheetFunction.Rept("0", Miao_Jingdu)) & "″"
End Function
'1.5---“度”化“度.分秒(小数)”函数
'JingDuWei指转化后秒的精度位数。

Public Function 度_度分秒_小数(角度_度 As Double) As Double
Dim FuHao As Integer
Dim D As Integer
Dim F As Integer
Dim M As Double
Dim JD As Double
FuHao = Sgn(角度_度)
JD = 角度_度 + 0.0000000000001 * FuHao
JD = Abs(JD)
D = Int(JD)
F = Int((JD - D) * 60)
M = ((JD - D) * 60 - F) * 60
If M > 59.9999 Then
M = 0
F = F + 1
If F = 60 Then
D = D + 1
F = 0
End If
End If
度_度分秒_小数 = FuHao * (D + F / 100 + M / 10000)
End Function
'1.6---“弧度”化“度.分秒(小数)函数
Public Function 弧度_度分秒_小数(角度_弧度 As Double) As Double
Dim JD As Double
JD = 角度_弧度 * 180 / PI
弧度_度分秒_小数 = 度_度分秒_小数(JD)
End Function
'1.7---“度”化“度分秒(空格)”函数
Public Function 度_度分秒_空格(角度_度 As Double, Optional 精度 As Integer = 0) As String
Dim fh As Integer
Dim D As Integer
Dim F As Integer
Dim M As Double
fh = Sgn(角度_度)
JD = 角度_度 + 0.0000000000001 * fh
JD = Abs(JD)
D = Int(JD)
F = Int((JD - D) * 60)
M = ((JD - D) * 60 - F) * 60
If 精度 > 0 Then
度_度分秒_空格= Space(4 - Len(Trim(Str$(D * fh)))) + Trim(Str$(D * fh)) _
+ Space(1) + Format(F, "00") + Space(1) + Format(M, "00." _
+
Application.WorksheetFunction.Rept("0", 精度))
Else
度_度分秒_空格= Space(4 - Len(Trim(Str$(D * fh)))) + Trim(Str$(D * fh)) _
+ Space(1) + Format(F, "00") + Space(1) + Format(M, "00")
End If
End Function
'1.8---“弧度”化“度分秒(空格)”函数
Public Function 弧度_度分秒_空格(弧度 As Double, Optional 精度 As Integer = 0) As String
Dim JD As Double
JD = 弧度 * 180 / PI
弧度_度分秒_空格 = 度_度分秒_空格(JD, 精度)
End Function
'1.9---“度.分秒”化“度分秒(空格)”函数
Public Function 度分秒小数_度分秒空格(度分秒 As Double, _
Optional 精度 As Integer = 0) As String
Dim fh As Integer
Dim D As Integer
Dim F As Integer
Dim M As Double
Dim dfm As Double
fh = Sgn(度分秒)
dfm = Abs(度分秒 + 0.0000000000001 * fh)
D = Int(dfm)
F = Int((dfm - D) * 100)
M = ((dfm - D) * 100 - F) * 100
If 精度 > 0 Then
度分秒小数_度分秒空格 = Space(4 - Len(Trim(Str$(D * fh)))) + _
Trim(Str$(D * fh)) + Space(1) + _
Format(F, "00") + Space(1) + Format(M, "00." _
+ Application.WorksheetFunction.Rept("0", 精度))
Else
度分秒小数_度分秒空格 = Space(4 - Len(Trim(Str$(D * fh)))) + _
Trim(Str$(D * fh)) + Space(1) + _
Format(F, "00") + Space(1) + Format(M, "00")
End If
End Function。

相关文档
最新文档