Contents
InternetExplorerオブジェクトを生成します。
iexplorer.exeのプロセスが残っているときにCREATEOLEOBJ関数でInternet Explorerを起動するとエラーが出ることがあるので、それを回避するための関数です。
- 構文
- InternetExplorer = IEBoot( [InPrivate] )
- 引数
- InPrivate
- InPrivateブラウズ・モードを有効にするときはTRUEを指定(デフォルトはFALSE)
プログラム
//////////////////////////////////////////////////
// 【引数】
// 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
//////////////////////////////////////////////////
// 【引数】
// 文字列 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
解説
- 2行目
- 起動したInternet Explorerを代入する変数。InternetExplorerオブジェクト。
DIM IE
- 5-7行目
- InPrivateブラウズ・モードで起動し、Internet Explorerオブジェクトを取得する。GETIDはウィンドウが表示されるまで待機するための処理。
DOSCMD("start iexplore -private") GETID("InPrivate - Internet Explorer - [InPrivate]", "IEFrame", -1) IE = GETACTIVEOLEOBJ("InternetExplorer.Application","InPrivate - Internet Explorer - [InPrivate]")
- 9-20行目
- Internet Explorerを起動する。エラーが発生した場合は、パスを指定して起動する。
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
- 22行目
- InternetExplorerオブジェクトを戻り値として返す。
RESULT = IE
プログラム実行例
bodyタグを書き換える
Yahoo! JAPANトップページの特定の文字を赤太字にする。
DIM IE = IEBoot()
IE.Navigate("www.yahoo.co.jp")
BusyWait(IE)
DIM body = IEGETSRC(IE, "body")
DIM array[] = "、", "。", "!", "?", "…", "・"
FOR item IN array
body = REPLACE(body, item, "<span style=<#DBL>color: red; font-weight: bold;<#DBL>>" + item + "</span>")
NEXT
PRINT IESETSRC(IE, body, "body")
//////////////////////////////////////////////////
// 【引数】
// 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
//////////////////////////////////////////////////
// 【引数】
// 文字列 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 = 5
SELEND
RESULT = ERR_VALUE
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
xmlのバージョンを取得する
DIM IE = IEBoot()
IE.Navigate("http://uwsc.s1007.xrea.com/sitemap.xml")
BusyWait(IE)
PRINT IE.document.xmlVersion
//////////////////////////////////////////////////
// 【引数】
// 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
//////////////////////////////////////////////////
// 【引数】
// 文字列 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 = 5
SELEND
RESULT = ERR_VALUE
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
- 結果
1.0
お問い合わせ番号から佐川急便の配達状況を取得
DIM IE = IEBoot()
DIM no = "000000000000" // お問い合わせ番号
IE.Navigate("http://k2k.sagawa-exp.co.jp/p/web/okurijosearch.do?okurijoNo=" + no)
BusyWait(IE)
DIM element, elements
element = IE.document.getElementById("1")
elements = element.getElementsByTagName("table")
elements = elements.Item(3)
DIM array[-1][-1]
getTableData(elements, array)
FOR r = 0 TO UBound(array)
DIM str = ""
FOR c = 0 TO UBound(array[0])
str = str + array[r][c] + ","
NEXT
PRINT str
NEXT
//////////////////////////////////////////////////
// 【引数】
// 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
//////////////////////////////////////////////////
// 【引数】
// 文字列 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 = 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
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
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
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
- IEBoot
- IE.Navigate
- BusyWait
- getElementById
- Elements.getElementsByClassName
- Elements.Item
- getTableData
- UBound
- 結果
荷物状況,日時,担当営業所, ↓集荷 ,12/14 17:00 ,○○営業所 , ↓輸送中 ,12/14 17:02 ,○○中継センター , ↓輸送中 ,12/15 01:23 ,○○中継センター , ↓配達中 ,12/16 07:32 ,○○営業所 , ⇒ご不在 ,12/16 12:10 ,○○営業所 ,
「Yahoo!テレビ.Gガイド [テレビ番組表]」から番組表データを取得する
CONST xlCenter = -4108
CONST xlTop = -4160
CONST xlContinuous = 1
CONST xlUp = -4162
CONST xlLastCell = 11
CONST xlGeneral = 1
HASHTBL rows
HASHTBL previousDay
GETTIME()
DIM date = G_TIME_YY4 + G_TIME_MM2 + G_TIME_DD2
DIM days[] = "日", "月", "火", "水", "木", "金", "土"
DIM dt = G_TIME_MM + "/" + G_TIME_DD + "<#CR>(" + days + ")"
DIM va = 24
DIM IE = IEBoot()
IE.Navigate("https://tv.yahoo.co.jp/listings/10/?&d=" + date + "&s=1&va=" + va + "&vb=1&vc=0&vd=0&ve=1&st=4")
BusyWait(IE)
DIM element, elements
element = IE.document.getElementById("Tables")
//elememts = element.getElementsByTagName("table")
elements = element.getElementsByClassName("turnup")
//elements = element.querySelector(".turnup")
SLEEP(3.00)
DIM Excel = ExcelBoot()
//Excel.Cells(1, 1).Interior.Color = 249 + 210 * 256 + 228 * 65536
Excel.Rows.RowHeight = 1
Excel.Columns.ColumnWidth = 35 // 22
WITH Excel.Cells
WITH .Font
.Size = 10
.Name = "メイリオ"
ENDWITH
.VerticalAlignment = xlTop
.WrapText = TRUE
ENDWITH
// フォント メイリオ
// サイズ 10
// 折り返して全体を表示
Excel.ScreenUpdating = FALSE
DIM num = elements.length
FOR i = 0 TO num - 1
FUKIDASI(i + "/" + (num-1))
WITH elements.Item(i)
TRY
DIM len = VAL(.getAttribute("rowspan"))
DIM time = .getElementsByClassName("time").Item(0).innerText
DIM times = SPLIT(time, ":")
DIM hour = VAL(times[0])
DIM minute = VAL(times[1])
DIM ttl = .getElementsByClassName("title").Item(0).innerText
DIM str = .getElementsByTagName("a").Item(0).dataset.ylk
DIM ch = VAL(COPY(str, POS("pos:", str) + 4))
DIM note = TRIM(getDirectChildText(.getElementsByClassName("detail").Item(0)))
IF hour < 24 THEN previousDay[ch] = TRUE
IF previousDay[ch] <> TRUE THEN hour = hour MOD 24
DIM row = hour * 60 + minute - 4 * 60 + 1
IFB row >= 0 THEN
TRY
WITH Excel
WITH .Cells(row, ch)
DIM text = time + " " + ttl + "<#CR>" + note
.Value = text
.Characters(LENGTH(time) + 2, LENGTH(ttl)).Font.FontStyle = "ボールド"
try
IFB LENGTH(note) > 0 THEN
.Characters(LENGTH(time + " " + ttl) + 2).Font.FontSize = 8
ELSE
ENDIF
except
endtry
ENDWITH
ENDWITH
EXCEPT
ENDTRY
ENDIF
SELECT TRUE
CASE POS("cellBGAnime", .outerHTML) <> 0
Excel.Cells(row, ch).Interior.Color = 249 + 210 * 256 + 228 * 65536
CASE POS("cellBGMusic", .outerHTML) <> 0
Excel.Cells(row, ch).Interior.Color = 253 + 228 * 256 + 206 * 65536
CASE POS("cellBGSports", .outerHTML) <> 0
Excel.Cells(row, ch).Interior.Color = 226 + 238 * 256 + 198 * 65536
CASE POS("cellBGDrama", .outerHTML) <> 0
Excel.Cells(row, ch).Interior.Color = 255 + 250 * 256 + 178 * 65536
CASE POS("cellBGMovie", .outerHTML) <> 0
Excel.Cells(row, ch).Interior.Color = 212 + 229 * 256 + 198 * 65536
CASE POS("GrayBg", .outerHTML) <> 0
Excel.Cells(row, ch).Interior.Color = 220 + 220 * 256 + 220 * 65536
SELEND
EXCEPT
print try_errline
ENDTRY
ENDWITH
NEXT
Excel.ScreenUpdating = TRUE
WITH Excel
FOR col = 1 TO 7
.ScreenUpdating = FALSE
DIM LastRow = va * 60
REPEAT
DIM Range = .Cells(LastRow, col).End(xlUp)
IFB .Cells(LastRow, col).Value <> "" THEN
LastRow = LastRow - 1
CONTINUE
ENDIF
IF LastRow - Range.Row > 1 THEN .Range(.Cells(Range.Row, col), .Cells(LastRow, col)).Merge
LastRow = Range.Row - 1
UNTIL Range.Row = 1
.ScreenUpdating = TRUE
NEXT
ENDWITH
// ch
elements = IE.document.getElementById("ListingsHeader")
elements = elements.getElementsByClassName("station")
WITH Excel
.Rows(1).Insert
.Rows(1).RowHeight = 30
ENDWITH
num = elements.length
FOR i = 0 TO num - 1
Excel.Cells(1, i + 1) = elements.Item(i).innerText
NEXT
WITH Excel.Range(Excel.Cells(1, 1), Excel.Cells(1, num))
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
ENDWITH
IE.Quit
//Excel.ScreenUpdating = FALSE
// じかんたい きにゅう
DIM h[] = 8, 3
FOR col IN h
WITH Excel
.Columns(col).Insert
.Columns(col).ColumnWidth = 3.5
FOR i = 0 TO 23
hour = i + 4
WITH .Cells(i * 60 + 2, col)
.Value = hour
SELECT TRUE
CASE hour >= 4 AND hour < 12
.Interior.Color = 250 + 198 * 256 + 0 * 65536
CASE hour >= 12 AND hour < 18
.Interior.Color = 188 + 209 * 256 + 0 * 65536
CASE hour >= 18 AND hour < 23
.Interior.Color = 56 + 171 * 256 + 224 * 65536
CASE hour >= 23
.Interior.Color = 2 + 80 * 256 + 138 * 65536
SELEND
ENDWITH
.Range(Excel.Cells(i * 60 + 2, col), Excel.Cells((i + 1) * 60 + 1, col)).Merge
NEXT
ENDWITH
WITH Excel.Columns(col)
.HorizontalAlignment = xlCenter
.Font.Bold = TRUE
.Font.Color = 255 + 255 * 256 + 255 * 65536
.Font.Size = 12
.VerticalAlignment = xlCenter
ENDWITH
NEXT
// けいせんをひく
DIM LastCell = Excel.Range("A1").SpecialCells(xlLastCell)
WITH Excel.Range("A1", Excel.Cells(LastCell.Row, LastCell.Column)).Borders
.LineStyle = xlContinuous
.ThemeColor = 1
.TintAndShade = -0.349986266670736
ENDWITH
WITH Excel.Range("J1:J200")
.Merge
.Value = dt
WITH .Font
.Size = 60
.Color = 255 + 255 * 256 + 255 * 65536
ENDWITH
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Interior.Color = 5296274 // へいじつ、どにち、しゅくじつ
ENDWITH
//Excel.ScreenUpdating = TRUE
// 要素直下のテキストを取得
FUNCTION getDirectChildText(element)
DIM res = ""
FOR elem IN element.childNodes
IF elem.nodeName = "#text" THEN res = res + elem.nodeValue
NEXT
RESULT = res
FEND
//////////////////////////////////////////////////
// 【引数】
// 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
//////////////////////////////////////////////////
// 【引数】
// interval : 加算する時間間隔を表す文字列式(yyyy:年、m:月、d:日、ww:週、h:時、n:分、s:秒)
// num : dateに加算する値。未来は正、過去は負で指定
// date : 時間間隔を加算する日付
// 【戻値】
// 日時(date)に、指定した単位(interval)の時間(num)を加算して返します
//////////////////////////////////////////////////
FUNCTION dateAdd(interval, num, date)
DIM year, month, day, d
GETTIME(0, date)
SELECT interval
CASE "yyyy"
d = (G_TIME_YY + num) + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
CASE "m"
IFB num > 0 THEN
year = G_TIME_YY + INT((G_TIME_MM + num - 1) / 12)
month = REPLACE(FORMAT(((G_TIME_MM + num) MOD 12), 2), " ", "0")
ELSE
year = G_TIME_YY + CEIL((G_TIME_MM + num) / 12 - 1)
month = REPLACE(FORMAT(G_TIME_MM - (ABS(num) MOD 12), 2), " ", "0")
ENDIF
IF month = "00" THEN month = "12"
day = G_TIME_DD2
d = "" + year + month + day
IFB !isDate(d) THEN
d = year + "/" + month + "/" + "01"
d = getEndOfMonth(d)
ELSE
d = year + "/" + month + "/" + day
ENDIF
CASE "d"
t = GETTIME(num, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "ww"
t = GETTIME(num * 7, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "h"
t = GETTIME(num / 24, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "n"
t = GETTIME(num / 1440, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "s"
t = GETTIME(num / 86400, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
// interval : 時間単位(yyyy︰年、q:四半期、m︰月、d︰日、w:週日、ww:週、h:時、n:分、s:秒)
// date1 : 日時1
// date2 : 日時2
// 【戻値】
// date2からdate1を引いた時間間隔を求めます。
//////////////////////////////////////////////////
FUNCTION dateDiff(interval, date1, date2)
DIM y1, y2, m1, m2, d1, d2, d
SELECT interval
CASE "yyyy"
GETTIME(0, date1)
y1 = G_TIME_YY
GETTIME(0, date2)
y2 = G_TIME_YY
d = y2 - y1
CASE "q"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = y2 * 4 + CEIL(m2/3) - (y1 * 4 + CEIL(m1/3))
CASE "m"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = (y2 - y1) * 12 + m2 - m1
CASE "d"
d1 = GETTIME(0, date1)
d2 = GETTIME(0, date2)
d = (d2 - d1) / 86400
CASE "w"
d = INT(dateDiff("d", date1, date2) / 7)
CASE "ww"
date1 = dateAdd("d", -1 * getWeekday(date1), date1)
d = INT(dateDiff("d", date1, date2) / 7)
CASE "h"
d = dateDiff("d", date1, date2) * 24
CASE "n"
d = dateDiff("d", date1, date2) * 1440
CASE "s"
d = dateDiff("d", date1, date2) * 86400
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
// path : 開くファイルのパス名
// 【戻値】
// Excelオブジェクト
//////////////////////////////////////////////////
FUNCTION ExcelBoot(path = "")
DIM Excel = CREATEOLEOBJ("Excel.Application")
Excel.Visible = TRUE
IFB path = "" THEN
Excel.Workbooks.Add
ELSE
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
IFB FSO.GetParentFolderName(path) = "" THEN
path = GET_CUR_DIR + "\" + path
ENDIF
Excel.Workbooks.Open(path)
ENDIF
RESULT = Excel
FEND
//////////////////////////////////////////////////
// 【引数】
// arr : 最大公約数を求める数値を格納した配列
// 【戻値】
// 最大公約数
//////////////////////////////////////////////////
FUNCTION GCD(arr[])
DIM c = LENGTH(arr)
DIM rem = arr[c-1] MOD arr[c-2]
IFB rem = 0 THEN
IFB LENGTH(arr) = 2 THEN
RESULT = arr[c-2]
EXIT
ENDIF
RESIZE(arr, c-2)
RESULT = GCD(arr)
EXIT
ENDIF
arr[c-1] = arr[c-2]
arr[c-2] = rem
RESULT = GCD(arr)
FEND
//////////////////////////////////////////////////
// 【引数】
// date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”)
// m : 第一引数の指定日からプラスマイナス m 月とする(デフォルト=0)
// 【戻値】
// date から m 月後の月末の日付
//////////////////////////////////////////////////
FUNCTION getEndOfMonth(date, m = 0)
date = dateAdd("m", m + 1, date)
GETTIME(0, date)
GETTIME(-G_TIME_DD, date)
RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
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 = 5
SELEND
RESULT = ERR_VALUE
FEND
//////////////////////////////////////////////////
// 【引数】
// 日付 : (”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”)
// 【戻値】
// 曜日 (0:日曜…、6:土曜)
//////////////////////////////////////////////////
FUNCTION getWeekday(date)
GETTIME(0, date)
RESULT = G_TIME_WW
FEND
//////////////////////////////////////////////////
// 【引数】
// 数値 : GETTIMEで取得した曜日の番号(G_TIME_WW=0:日曜….6:土曜)
// フォーマット : 以下のアルファベットは数値で指定した対応する曜日に置き換えられます。(aaa : 日〜土、aaaa : 日曜日〜土曜日、ddd : Sun〜Sat、dddd : Sunday〜Saturday)
// 【戻値】
// 数値をフォーマットした文字列を返します。
//////////////////////////////////////////////////
FUNCTION getWeekdayName(num, format = "aaa")
DIM re = CREATEOLEOBJ("VBScript.RegExp")
DIM aaa[] = "日", "月", "火", "水", "木", "金", "土";
DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日";
DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat";
DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
match = reExecute(format, "(a|d)+")
type = match.Item(0).Value
RESULT = reReplace(format, EVAL(type + "[" + num + "]"), type)
FEND
//////////////////////////////////////////////////
// 【引数】
// シリアル値 : 時間を表すシリアル値を指定
// 【戻値】
// 例)0…00、0.5…12、1.0…24
//////////////////////////////////////////////////
FUNCTION Hour(serial)
RESULT = REPLACE(FORMAT(INT(serial * 24), 2), " ", "0")
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
//////////////////////////////////////////////////
// 【引数】
// expr : 評価する式
// truepart : 評価した式がTrueのときに返す値
// falsepart : 評価した式がFalseのときに返す値
// 【戻値】
// truepart : 評価した式がTrueのとき、falsepart : 評価した式がFalseのとき
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
IFB EVAL(expr) THEN
RESULT = truepart
ELSE
RESULT = falsepart
ENDIF
FEND
//////////////////////////////////////////////////
// 【引数】
// 日付 : YYYYMMDD
// 【戻値】
// TRUE : 日付として認識できる、FALSE : 日付として認識できない
//////////////////////////////////////////////////
FUNCTION isDate(date)
DIM Pattern = "^(?!([02468][1235679]|[13579][01345789])000229)(([0-9]{4}(01|03|05|07|08|10|12)(0[1-9]|[12][0-9]|3[01]))|([0-9]{4}(04|06|09|11)(0[1-9]|[12][0-9]|30))|([0-9]{4}02(0[1-9]|1[0-9]|2[0-8]))|([0-9]{2}([02468][048]|[13579][26])0229))$"
DIM Match = reExecute(date, Pattern)
RESULT = IIF(Match.Count 0, TRUE, FALSE)
FEND
//////////////////////////////////////////////////
// 【引数】
// str : 正規表現による検索の対象となる文字列
// Pattern : 正規表現で使用するパターンを設定
// IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse
// Global : 文字列全体を検索する場合はTrue、しない場合はFalse
// 【戻値】
// 正規表現で検索した結果をMatchesコレクションとして返します。
//////////////////////////////////////////////////
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Execute(str)
FEND
//////////////////////////////////////////////////
// 【引数】
// str1 : 置換される文字列
// str2 : 置換後の文字列
// Pattern : 置換する文字列のパターン
// IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse
// Global : 文字列全体を検索する場合はTrue、しない場合はFalse
// 【戻値】
// 正規表現置換後の文字列
//////////////////////////////////////////////////
FUNCTION reReplace(str1, str2, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Replace(str1, str2)
FEND
//////////////////////////////////////////////////
// 【引数】
// str : 正規表現による検索の対象となる文字列
// Pattern : 正規表現で使用するパターンを設定
// IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse
// Global : 文字列全体を検索する場合はTrue、しない場合はFalse
// 【戻値】
// 正規表現にマッチするかどうか
//////////////////////////////////////////////////
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Test(str)
FEND
//////////////////////////////////////////////////
// 【引数】
// inputs : 繰り返す文字列
// multiplier : inputsを繰り返す回数
// 【戻値】
// inputsをmultiplier回を繰り返した文字列を返します
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
DIM res = ""
FOR n = 1 TO multiplier
res = res + inputs
NEXT
RESULT = res
FEND
//////////////////////////////////////////////////
// 【引数】
// serial : シリアル値
// format : フォーマット
// 【戻値】
// 数値を表示書式に基づいて変換した文字列
//////////////////////////////////////////////////
FUNCTION text(serial, format, hour12 = FALSE)
HASHTBL startDate
startDate["明治"] = "1868/01/25"
startDate["大正"] = "1912/07/30"
startDate["昭和"] = "1926/12/25"
startDate["平成"] = "1989/01/08"
startDate["令和"] = "2019/05/01"
DIM baseDate = "1899/12/30"
SELECT TRUE
CASE reTest(format, "\[h+\]")
Matches = reExecute(format, "\[(h+)\]")
DIM hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "^h+$")
Matches = reExecute(format, "^(h+)$")
hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour MOD 24, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "\[m+\]")
Matches = reExecute(format, "\[(m+)\]")
RESULT = text(serial * 1440, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE format = "m"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_MM, "0")
CASE format = "mm"
GETTIME(serial, baseDate)
RESULT = G_TIME_MM2
CASE format = "n"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN
CASE format = "nn"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN2
CASE format = "s"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_SS, "0")
CASE format = "ss"
GETTIME(serial, baseDate)
RESULT = G_TIME_SS2
CASE format = "yyyy"
GETTIME(serial, baseDate)
RESULT = G_TIME_YY4
CASE format = "yy"
GETTIME(serial, baseDate)
RESULT = COPY(G_TIME_YY4, 3, 2)
CASE format = "e"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 2018
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1988
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1925
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1911
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1867
SELEND
CASE format = "ee"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 2018, "00")
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1988, "00")
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1925, "00")
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1911, "00")
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1867, "00")
SELEND
CASE format = "g"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "R"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "H"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "S"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "T"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "M"
SELEND
CASE format = "gg"
RESULT = COPY(text(serial, "ggg"), 1, 1)
CASE format = "ggg"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "令和"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "平成"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "昭和"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "大正"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0; RESULT = "明治"
SELEND
CASE format = "mmmmm"
RESULT = COPY(text(serial, "mmmm"), 1, 1)
CASE format = "mmmm"
DIM month[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
RESULT = month[text(serial, "m") - 1]
CASE format = "mmm"
RESULT = COPY(text(serial, "mmmm"), 1, 3)
CASE format = "dd"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD2, "00")
CASE format = "d"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD, "0")
CASE reTest(format, "^[ad]{3,4}$")
Matches = reExecute(format, "([ad]{3,4})")
GETTIME(serial, baseDate)
RESULT = getWeekdayName(G_TIME_WW, Matches.Item(0).SubMatches(0))
CASE reTest(format, "(0+\.?0+)?%")
Matches = reExecute(format, "(0+\.?0+)?%")
RESULT = text(serial * 100, Matches.Item(0).SubMatches(0)) + "%"
CASE reTest(format, "^\[DBNum\d{1,4}\](.*?)$")
Matches = reExecute(format, "^\[DBNum(\d{1,4})\](.*?)$")
DIM value = VAL(Matches.Item(0).SubMatches(0))
DIM sss = text(serial, Matches.Item(0).SubMatches(1))
Matches = reExecute(sss, "(\D+)?(\d+)(\D+)?")
DIM res = ""
FOR m = 0 TO Matches.Count - 1
serial = Matches.Item(m).SubMatches(1)
SELECT value
CASE 1, 2
DIM n[][9] = "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", + _
"", "壱", "弐", "参", "四", "伍", "六", "七", "八", "九"
DIM a[][3] = "", "十", "百", "千", + _
"", "拾", "百", "阡"
DIM b[][3] = "", "万", "億", "兆", + _
"", "萬", "億", "兆"
DIM r = ""
DIM j = 0
type = value - 1
REPEAT
DIM str = ""
DIM n4 = serial MOD 10000
FOR i = LENGTH(n4) TO 1 STEP -1
s = COPY(n4, i, 1)
IFB s = 1 AND a[type][LENGTH(n4)-i] "" THEN
str = IIF(s, a[type][LENGTH(n4)-i], "") + str
ELSE
str = n[type][s] + IIF(s, a[type][LENGTH(n4)-i], "") + str
ENDIF
NEXT
IF str "" THEN r = str + b[type][j] + r
j = j + 1
serial = INT(serial / 10000)
UNTIL serial = 0
res = res + Matches.Item(m).SubMatches(0) + r + Matches.Item(m).SubMatches(2)
CASE 3
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_FULLWIDTH) + Matches.Item(m).SubMatches(2)
CASE 4
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_HALFWIDTH) + Matches.Item(m).SubMatches(2)
SELEND
NEXT
RESULT = res
CASE reTest(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
Matches = reExecute(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
DIM array = SPLIT(Matches.Item(0).SubMatches(1), "/")
ampm = array[IIF(serial - INT(serial) >= 0.5, 1, 0)]
hour12 = TRUE
res = ""
WITH Matches.Item(0)
res = text(serial, .SubMatches(0), hour12) + ampm + text(serial, .SubMatches(2), hour12)
ENDWITH
RESULT = res
CASE reTest(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
Matches = reExecute(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
FOR n = 0 TO Matches.Count - 1
IF n = 0 THEN res = Matches.Item(n).SubMatches(0)
NEXT
FOR n = 0 TO Matches.Count - 1
WITH Matches.Item(n)
res = res + text(serial, .SubMatches(1), hour12) + .SubMatches(3)
ENDWITH
NEXT
RESULT = res
CASE format = "0/0"
DIM separator = POS(".", serial)
DIM g = 0
IFB separator 0 THEN
DIM keta = LENGTH(serial)
DIM shift = POWER(10, keta - separator)
IFB shift >= POWER(10, 15) THEN
DIM position = 0
FOR i = 0 TO 14
IFB serial * POWER(10, i) - serial >= 1 THEN
position = i
BREAK
ENDIF
NEXT
tmp = serial * POWER(10, position)
FOR i = 1 TO 15
r = (tmp * POWER(10, i)) / serial - (tmp / serial)
a1 = tmp * POWER(10, i) - tmp
IF a1 = INT(a1) THEN BREAK
NEXT
DIM frac[] = a1, r
g = GCD(frac)
RESULT = (a1/g) + "/" + (r/g)
ELSE
DIM molecule = serial * shift // 分子
DIM denominator = shift // 分母
DIM nums[] = molecule, denominator
g = GCD(nums)
molecule = molecule / g
denominator = denominator / g
RESULT = molecule + "/" + denominator
ENDIF
ELSE
RESULT = serial + "/1"
ENDIF
CASE reTest(format, "(0+)\.?(0+)?") AND UBound(SPLIT(format, "."))
GoBackとGoForwardを使った例
DIM IE = IEBoot()
IE.Navigate("http://www.google.com")
BusyWait(IE)
IE.Navigate("https://www.yahoo.co.jp")
BisyWait(IE)
IE.GoBack // 前のページ(Google)を開く
BusyWait(IE)
SLEEP(5.000)
IE.GoForward // 次のページ(Yahoo!)を開く
BusyWait(IE)
SLEEP(5.000)
IE.Quit
//////////////////////////////////////////////////
// 【引数】
// 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
//////////////////////////////////////////////////
// 【引数】
// 文字列 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 = 5
SELEND
RESULT = ERR_VALUE
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
気象庁のホームページから一月分の気温を取得しExcelでグラフを作成
CONST xlUp = -4162
CONST xlLineMarkers = 65
DIM year = 2020
DIM month = 8
DIM IE = IEBoot()
IE.Navigate("https://www.data.jma.go.jp/obd/stats/etrn/view/daily_s1.php?prec_no=14&block_no=47412&year=" + year + "&month=" + month + "&day=&view=p1")
BusyWait(IE)
DIM array[-1][-1]
DIM element = IE.document.getElementById("tablefix1")
getTableData(element, array)
IE.Quit
DIM Excel = XLOPEN()
DIM SheetName = Excel.ActiveSheet.Name
XLSETDATA(Excel, array, "A1")
DIM row = Excel.Cells(Excel.Rows.Count, 1).End(xlUp).Row
DIM Charts = Excel.Charts.Add
WITH Charts
.ChartType = xlLineMarkers
.SeriesCollection.NewSeries
.HasTitle = TRUE
.ChartTitle.Text = "札幌 " + year + "年" + month + "月気温"
WITH .FullSeriesCollection(1)
.XValues = "=Sheet1!$A$5:$A$35"
.Name = "=<#DBL>最高気温<#DBL>"
.Values = "=Sheet1!$H$5:$H$35"
WITH .Format
.Fill.ForeColor.RGB = 255
.Line.ForeColor.RGB = 255
ENDWITH
ENDWITH
WITH .FullSeriesCollection(2)
.XValues = "=Sheet1!$A$5:$A$35"
.Name = "=<#DBL>最高気温<#DBL>"
.Values = "=Sheet1!$I$5:$I$35"
WITH .Format
.Fill.ForeColor.RGB = 16711680
.Line.ForeColor.RGB = 16711680
ENDWITH
ENDWITH
ENDWITH
//////////////////////////////////////////////////
// 【引数】
// 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
//////////////////////////////////////////////////
// 【引数】
// 文字列 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 = 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
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
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
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
- IEBoot
- IE.Navigate
- BusyWait
- document.getElementById
- getTableData
- XLOPEN
- Excel.Application.ActiveSheet
- Excel.WorkSheet.Name
- XLSETDATA
- Excel.Application.Cells
- Excel.Range.End
- Excel.Range.Row
- Excel.Application.Charts
- Excel.Sheets.Add
- Excel.Charts
- Excel.Chart.ChartType
- Excel.Chart.SeriesCollection
- Excel.SeriesCollection.NewSeries
- Excel.Series
- Excel.Chart.HasTitle
- Excel.Chart.ChartTitle
- Excel.ChartTitle.Text
- Excel.Chart.FullSeriesCollection
- Excel.FullSeriesCollection
- Excel.FullSeriesCollection.Item
- Excel.Series.XValues
- Excel.Series.Name
- Excel.Series.Values
- Excel.Series.Format
- Excel.FillFormat.ForeColor
- Excel.ColorFormat.RGB
- Excel.LineFormat.FontColor
- 結果
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) + ""
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 = 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
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
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
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
- IEBoot
- IE.Navigate
- BusyWait
- GETID
- CTRLWIN
- document.getElementById
- Element.getElementsByTagName
- Elements.Item
- getTableData
- UBound
- TRIM
- POS
- REPLACE
- SPLIT
- degToDMS
関連記事
- BusyWait
- 引数に指定したInternetExplorerオブジェクトの読み込みが完了するのを待ちます。
- getIEObj
- 引数に指定した「タイトル」または「URL」を含むInternetExplorerオブジェクトを返します。数値nを指定した場合、n番目に開いたInternetExplorerオブジェクトを取得します。負の数で後ろからn番目。IELINK関数で開かれた新しいタブのInternetExplorerオブジェクトを取得したいときに使います。
- IENoticeBar
- Web上でファイルをダウンロードしたときに出る通知バーの制御を行います。ダウンロードしたファイル名を返します。
- getTableData
- Web上のtableタグのデータを取得し、二次元配列に格納します。
- altClick
- Web上(IE)の指定したalt属性を含む画像をクリックします。クリックに成功した場合はTrue、失敗した場合はFalseを返します。
- DownloadFile
- 指定したURLのファイルをダウンロードします。第一引数にダウンロードするファイルのURL、第二引数にダウンロード先のフォルダ名、第三引数にダウンロードするファイル名を指定します。ダウンロードに成功した場合はTrue、失敗した場合はFalseを返します。