度分秒转换函数
度分秒轉換函數
- 調用例子
- 度分秒轉度
- 度轉度分秒
調用例子
也可以用于小時、分鐘、秒的轉換,但中間的分隔符只能是一位
MsgBox DToDMS(1.51, "度分秒") MsgBox DMSToD("12度3分4秒") MsgBox DMSToD("12h3m4.56s") MsgBox DMSToD("12°3'4"")度分秒轉度
支持度分秒之間使用任意非數字字符分隔,支持度分秒中存在小數
Function DMStoD(DMS As String) Dim sp(2) As Single Dim i As Integer Dim sta As IntegerOn Error Resume Next DMS = Trim(DMS) Do While IsNumeric(Mid(DMS, i, 1)) Or Mid(DMS, i, 1) = "."i = i + 1 Loopsp(0) = Left(DMS, i - 1) Do Until IsNumeric(Mid(DMS, i, 1)) Or i > Len(DMS)i = i + 1 Loop If i <= Len(DMS) Thensta = iDo While IsNumeric(Mid(DMS, i, 1)) Or Mid(DMS, i, 1) = "."i = i + 1Loopsp(1) = Mid(DMS, sta, i - sta)Do Until IsNumeric(Mid(DMS, i, 1)) Or i > Len(DMS)i = i + 1LoopIf i <= Len(DMS) Thensta = iDo While IsNumeric(Mid(DMS, i, 1)) Or Mid(DMS, i, 1) = "."i = i + 1Loopsp(2) = Mid(DMS, sta, i - sta)End If End If DMStoD = Round(sp(0) + sp(1) / 60 + sp(2) / 3600, 4) End Function度轉度分秒
支持自定義分隔符,支持自定義秒的小數位數
Function DToDMS(D As Single, Optional SpStr As String = "°'""", Optional Deci As Long = 0) Dim sp(2) As String sp(0) = Int(D) sp(1) = Int((D - sp(0)) * 60) sp(2) = Round((D - sp(0) - sp(1) / 60) * 60 * 60, Deci) DToDMS = sp(0) & Mid(SpStr, 1, 1) & sp(1) & Mid(SpStr, 2, 1) & sp(2) & Mid(SpStr, 3, 1) End Function——專注辦公軟件的二次開發及培訓,你有問題,我有思路!
——微博、微信、CSDN同號:w_dexu。
——轉載請注明出處!
掃碼加微信
總結
- 上一篇: 基于javafx+sqlserver的仓
- 下一篇: CUDA线程、线程块、线程束、流多处理器