Help us understand the problem. What is going on with this article?

Access Excel 緯度 経度 130度45分15.001秒 S20度22分30秒を130.000 -20.0000に変換する関数

More than 1 year has passed since last update.

グローバル対応

正規表現を参照設定します。
各数字は正規表現で抜き出し、文字をカットする手法です。
また、西経、南緯はマイナス表記になります。
このため、文字列の最初か最後にW、Sが付けばマイナスにしています。
小数点以下が続くので倍精度Double形式です

'https://oshiete.goo.ne.jp/qa/8901355.html
''正負、NESWがある場合。正規表現を使用するので参照設定
Public Function DMStoSignGbl(str) As Double
Dim DegreeLng As Long, MinDbl As Double, SecDbl As Double
Dim Reg As RegExp: Set Reg = New RegExp
Dim M As Match, MC As MatchCollection, iM As Long, lSgn As Long
Reg.Global = True: Reg.MultiLine = True: Reg.IgnoreCase = False
Reg.Pattern = "(\-[0-9]{1,3}度|[0-9]{1,3}度)" '正負を想定して
Set MC = Reg.Execute(str)
If MC.Count > 0 Then Set M = MC(0)
DegreeLng = Abs(Replace(M.Value, "度", "", 1, 1, vbTextCompare))
If DegreeLng <> Replace(M.Value, "度", "", 1, 1, vbTextCompare) Then lSgn = Sgn(Replace(M.Value, "度", "", 1, 1, vbTextCompare))
Reg.Pattern = "(^S|S$|^W|W$)" 'S,Wが最初か最後にあれば符号はマイナス
If Reg.Test(str) = True Then lSgn = Sgn(True)
Reg.Pattern = "(度[0-9]{1,2}分)"
Set MC = Reg.Execute(str)
If MC.Count > 0 Then Set M = MC(0)
MinDbl = (Replace(Replace(M.Value, "度", "", 1, 1, vbTextCompare), "分", "", 1, 1, vbTextCompare)) / 60
Reg.Pattern = "分[0-9]{0,}.[0-9]{0,}秒" 'この場合のピリオドは小数点ではなく任意の1文字
Set MC = Reg.Execute(str)
If MC.Count > 0 Then Set M = MC(0)
SecDbl = (Replace(Replace(M.Value, "分", "", 1, 1, vbTextCompare), "秒", "", 1, 1, vbTextCompare)) / 3600
If lSgn <> 0 Then DMStoSignGbl = (DegreeLng + MinDbl + SecDbl) * lSgn Else DMStoSignGbl = DegreeLng + MinDbl + SecDbl '符号に注意して返す
End Function
Q11Q
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした