IEBoot

InternetExplorerオブジェクトを生成します。

iexplorer.exeのプロセスが残っているときにCREATEOLEOBJ関数でInternet Explorerを起動するとエラーが出ることがあるので、それを回避するための関数です。

構文
  1. InternetExplorer = IEBoot( [InPrivate] )
引数
InPrivate
InPrivateブラウズ・モードを有効にするときはTRUEを指定(デフォルトはFALSE)
戻値
InternetExplorerオブジェクト

プログラム

//////////////////////////////////////////////////
// 【引数】
//   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

解説

  1. 2行目
    	DIM IE
    
    起動したInternet Explorerを代入するInternetExplorerオブジェクト。
  2. 3行目
    	SELECT InPrivate
    
    変数InPrivateの値が
    TRUE
    5行目>>>
    FALSE
    9行目>>>
  3. 5-7行目
    			DOSCMD("start iexplore -private")
    			GETID("InPrivate - Internet Explorer - [InPrivate]", "IEFrame", -1)
    			IE = GETACTIVEOLEOBJ("InternetExplorer.Application","InPrivate - Internet Explorer - [InPrivate]")
    
  4. 9-20行目
    			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
    
  5. 22行目
    	RESULT = IE
    

プログラム実行例

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 < 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

//////////////////////////////////////////////////
// 【引数】
//   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

「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︰日) 
//   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 "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
	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

//////////////////////////////////////////////////
// 【引数】
//   文字列 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

//////////////////////////////////////////////////
// 【引数】
//   数値 : 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

//////////////////////////////////////////////////
// 【引数】
//   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)
	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+)\]")
			RESULT = text(Hour(serial), strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
		CASE reTest(format, "^h+$")
			Matches = reExecute(format, "^(h+)$")
			RESULT = text(Hour(serial) 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"
			SELECT text(serial, "m")
				CASE 1;  RESULT = "January"
				CASE 2;  RESULT = "February"
				CASE 3;  RESULT = "March"
				CASE 4;  RESULT = "April"
				CASE 5;  RESULT = "May"
				CASE 6;  RESULT = "June"
				CASE 7;  RESULT = "July"
				CASE 8;  RESULT = "August"
				CASE 9;  RESULT = "September"
				CASE 10; RESULT = "October"
				CASE 11; RESULT = "November"
				CASE 12; RESULT = "December"
			SELEND
		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 format = "aaaa"
			GETTIME(serial, baseDate)
			RESULT = getWeekdayName(G_TIME_WW, "aaaa")
		CASE format = "aaa"
			GETTIME(serial, baseDate)
			RESULT = getWeekdayName(G_TIME_WW, "aaa")
		CASE format = "dddd"
			GETTIME(serial, baseDate)
			RESULT = getWeekdayName(G_TIME_WW, "dddd")
		CASE format = "ddd"
			GETTIME(serial, baseDate)
			RESULT = getWeekdayName(G_TIME_WW, "ddd")
		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})\](.*?)$")
			SELECT Matches.Item(0).SubMatches(0)
				CASE 1
					
				CASE 2
					
				CASE 3
					RESULT = STRCONV(text(serial, Matches.Item(0).SubMatches(1)), SC_FULLWIDTH)
				CASE 4
					
			SELEND
		CASE reTest(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
			Matches = reExecute(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
			res = ""
			WITH Matches.Item(0)
				res = text(serial, .SubMatches(0)) + .SubMatches(1) + text(serial, .SubMatches(2))
			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)) + .SubMatches(3)
				ENDWITH
			NEXT
			RESULT = res
		CASE reTest(format, "(0+)\.?(0+)?") AND UBound(SPLIT(format, ".")) <= 1 
			Matches = reExecute(format, "(0+)\.?(0+)?")
			len1 = LENGTH(Matches.Item(0).SubMatches(0))
			len2 = LENGTH(Matches.Item(0).SubMatches(1))
			DIM arr[] = LENGTH(INT(serial)), len1
			IFB POS(".", format) THEN
				RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX) + len2 + 1, len2), " ", "0")
			ELSE
				RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX)), " ", "0")
			ENDIF
	SELEND
FEND

//////////////////////////////////////////////////
// 【引数】
//   配列 : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
	RESULT = RESIZE(array)
FEND

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 < 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

//////////////////////////////////////////////////
// 【引数】
//   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