degToDMS

角度を度形式から度分秒形式に変換します。

度分秒形式から度に変換するにはDMSToDegを使います。

構文
  1. String = degToDMS( deg )
引数
deg
角度(°)
戻値
角度(deg°分'秒")

プログラム

//////////////////////////////////////////////////
// 【引数】
//   deg : 角度(°) 
// 【戻値】
//   角度(deg°分'秒") 
//////////////////////////////////////////////////
FUNCTION degToDMS(deg)
	DIM degree = INT(deg)
	DIM minute = (deg - INT(deg)) * 60
	DIM second = ROUND(minute - INT(minute), -10) * 60
	RESULT = degree + "°" + INT(minute) + "'" + ROUND(second, -5) + "<#DBL>"
FEND

プログラム実行例

Yahoo!天気・災害情報より直近に発生した地震情報を取得しその場所をGoogleマップで表示

DIM IE = IEBoot()
IE.Navigate("http://typhoon.yahoo.co.jp/weather/earthquake/")
BusyWait(IE)

DIM ID = GETID("地震情報")
CTRLWIN(ID, MAX)

DIM array[-1][-1]
DIM element = IE.document.getElementById("eqinfdtl")
DIM elements = element.getElementsByTagName("table")
element = elements.Item(0)

getTableData(element, array)

HASHTBL tbl

FOR r = 0 TO UBound(array)
	tbl[TRIM(array[r][0])] = array[r][1]
NEXT

DIM way[1]

IF POS("北緯", tbl["緯度/経度"]) THEN way[0] = "N"
IF POS("東経", tbl["緯度/経度"]) THEN way[1] = "E"
IF POS("西経", tbl["緯度/経度"]) THEN way[1] = "W"
IF POS("南緯", tbl["緯度/経度"]) THEN way[0] = "S"

tbl["緯度/経度"] = REPLACE(tbl["緯度/経度"], "度", "")
tbl["緯度/経度"] = REPLACE(tbl["緯度/経度"], "北緯", "")
tbl["緯度/経度"] = REPLACE(tbl["緯度/経度"], "東経", "")
tbl["緯度/経度"] = REPLACE(tbl["緯度/経度"], "西経", "-")
tbl["緯度/経度"] = REPLACE(tbl["緯度/経度"], "南緯", "-")

DIM coordinate = SPLIT(TRIM(tbl["緯度/経度"]), "/")
DIM z = 7
DIM url = "https://www.google.co.jp/maps/place/" + degToDMS(coordinate[0]) + way[0] + "," + degToDMS(coordinate[1]) + way[1] + "/@" + coordinate[0] + "," + coordinate[1] + "," + z + "z/"
url = REPLACE(url, "°", "%C2%B0")
url = REPLACE(url, "<#DBL>", "")

IE.Navigate(url)
BusyWait(IE)

//////////////////////////////////////////////////
// 【引数】
//   IE : IEオブジェクト 
// 【戻値】
// 
//////////////////////////////////////////////////
PROCEDURE BusyWait(Var IE)
	SLEEP(0.500)
	DIM t = GETTIME()
	TRY
		REPEAT
			DIM tm = GETTIME() - t
			FUKIDASI("BusyWait:" + tm)
			SLEEP(0.010)
			IF tm >= 60 THEN BREAK
		UNTIL !IE.Busy AND IE.readyState = 4
	EXCEPT
		IE = getIEObj(-1)
		PRINT IE.document.URL + " のIEオブジェクトを取得しました。"
		BusyWait(IE)
	ENDTRY
	FUKIDASI()
FEND

//////////////////////////////////////////////////
// 【引数】
//   deg : 角度(°) 
// 【戻値】
//   角度(deg°分'秒") 
//////////////////////////////////////////////////
FUNCTION degToDMS(deg)
	DIM degree = INT(deg)
	DIM minute = (deg - INT(deg)) * 60
	DIM second = ROUND(minute - INT(minute), -10) * 60
	RESULT = degree + "°" + INT(minute) + "'" + ROUND(second, -5) + "<#DBL>"
FEND

//////////////////////////////////////////////////
// 【引数】
//   文字列 or 数値 : 取得したいIEオブジェクトのタイトル・URLもしくは数値を指定 
//   完全一致フラグ : (TRUE : 文字列が完全一致したものを取得、FALSE : 文字列の一部を含むものを取得) 
// 【戻値】
//   Internet Explorerオブジェクト 
//////////////////////////////////////////////////
FUNCTION getIEObj(str, flg = FALSE)
	DIM Shell = CREATEOLEOBJ("Shell.Application")
	SELECT CHKNUM(str)
		CASE TRUE
			DIM cnt = 0
			SELECT TRUE
				CASE str > 0
					FOR n = 0 TO Shell.Windows.Count - 1
						TRY
							IFB Shell.Windows.Item(n).Name = "Internet Explorer" THEN
								cnt = cnt + 1
								IFB str = cnt THEN
									RESULT = Shell.Windows.Item(n)
									EXIT
								ENDIF
							ENDIF
						EXCEPT
						ENDTRY
					NEXT
				CASE str < 0
					FOR n = Shell.Windows.Count - 1 TO 0 STEP -1
						TRY
							IFB Shell.Windows.Item(n).Name = "Internet Explorer" THEN
								cnt = cnt + 1
								IFB ABS(str) = cnt THEN
									RESULT = Shell.Windows.Item(n)
									EXIT
								ENDIF
							ENDIF
						EXCEPT
						ENDTRY
					NEXT
				CASE str = 0
					FOR n = 0 TO Shell.Windows.Count - 1
						TRY
							IF Shell.Windows.Item(n).Name = "Internet Explorer" THEN cnt = cnt + 1
						EXCEPT
						ENDTRY
					NEXT
					RESULT = cnt
					EXIT
			SELEND
		CASE FALSE
			DIM t = GETTIME()
			REPEAT
				FOR n = 0 TO Shell.Windows.Count - 1
					TRY
						DIM targetObj = Shell.Windows.Item(n)
						IFB targetObj.Name = "Internet Explorer" THEN
							SELECT flg
								CASE TRUE
									IFB targetObj.document.title = str OR targetObj.LocationURL = str THEN
										RESULT = Shell.Windows.Item(n)
										EXIT
									ENDIF
								CASE FALSE
									IFB POS(str, targetObj.document.title) OR POS(str, targetObj.LocationURL) THEN
										RESULT = Shell.Windows.Item(n)
										EXIT
									ENDIF
							SELEND
						ENDIF
					EXCEPT
					ENDTRY
				NEXT
			UNTIL GETTIME() - t >= 5
	SELEND
	RESULT = ERR_VALUE
FEND

//////////////////////////////////////////////////
// 【引数】
//   table : tableエレメント 
//   arr : 取得したデータを格納する配列(参照引数) 
// 【戻値】
// 
//////////////////////////////////////////////////
PROCEDURE getTableData(table, Var arr[][])
	rowMax = table.rows.length - 1
	colMax = 0
	FOR row = 0 TO table.rows.length - 1
		IFB table.rows(row).cells.length - 1 > colMax THEN
			colMax = table.rows(row).cells.length - 1
		ENDIF
	NEXT
	DIM arr[rowMax][colMax]
	FOR row = 0 TO table.rows.length - 1
		FOR col = 0 TO table.rows(row).cells.length - 1
			n = 0
			WHILE arr[row][col + n] <> ""
				n = n + 1
			WEND
			arr[row][col + n] = table.rows(row).cells(col).innerText
			// rowSpan(行結合)とcolSpan(列結合)の両方があれば
			IFB table.rows(row).cells(col).rowSpan > 1 AND table.rows(row).cells(col).colSpan > 1 THEN
				rmax = table.rows(row).cells(col).rowSpan - 1
				cmax = table.rows(row).cells(col).colSpan - 1
				FOR r = 1 TO rmax
					FOR c = 1 TO cmax
						arr[row + r][col + c] = "←"
					NEXT
				NEXT
			ENDIF
			// rowSpan(行結合)があれば結合セルに「↑」を代入
			IFB table.rows(row).cells(col).rowSpan > 1 THEN
				n = table.rows(row).cells(col).rowSpan - 1
				WHILE n
					arr[row + n][col] = "↑"
					n = n - 1
				WEND
			ENDIF
			// colSpan(列結合)があれば結合セルに「←」を代入
			IFB table.rows(row).cells(col).colSpan > 1 THEN
				n = table.rows(row).cells(col).colSpan - 1
				WHILE n
					arr[row][col + n] = "←"
					n = n - 1
				WEND
			ENDIF
		NEXT
	NEXT
FEND

//////////////////////////////////////////////////
// 【引数】
//   InPrivate : InPrivateブラウズ・モードを有効にするときはTRUEを指定(デフォルトはFALSE) 
// 【戻値】
//   InternetExplorerオブジェクト 
//////////////////////////////////////////////////
FUNCTION IEBoot(InPrivate = FALSE)
	DIM IE
	SELECT InPrivate
		CASE TRUE
			DOSCMD("start iexplore -private")
			GETID("InPrivate - Internet Explorer - [InPrivate]", "IEFrame", -1)
			IE = GETACTIVEOLEOBJ("InternetExplorer.Application","InPrivate - Internet Explorer - [InPrivate]")
		CASE FALSE
			TRY
				IE = CREATEOLEOBJ("InternetExplorer.Application")
				IE.Visible = TRUE
			EXCEPT
				EXEC("C:\Program Files\Internet Explorer\iexplore.exe")
				GETID("Internet Explorer", "IEFrame", -1)
				TRY
					IE = GETACTIVEOLEOBJ("InternetExplorer.Application")	
				EXCEPT
					IE = getIEObj(-1)
				ENDTRY
			ENDTRY
	SELEND
	RESULT = IE
FEND

//////////////////////////////////////////////////
// 【引数】
//   配列 : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
	RESULT = RESIZE(array)
FEND
  1. IEBoot
  2. IE.Navigate
  3. BusyWait
  4. GETID
  5. CTRLWIN
  6. document.getElementById
  7. Element.getElementsByTagName
  8. Elements.Item
  9. getTableData
  10. UBound
  11. TRIM
  12. POS
  13. REPLACE
  14. SPLIT
  15. degToDMS