GetDetailsOf

フォルダ内のアイテムに関する詳細を取得します。

構文
retVal = Folder.GetDetailsOf( vItem, iColumn )
引数
vItem
情報を取得する項目。これはFolderItemオブジェクトである必要があります。
iColumn
取得する情報を指定するInteger値。アイテムに利用できる情報は、アイテムが表示されているフォルダによって異なります。この値は、シェルビューに表示されるゼロベースの列番号に対応します。
戻値
iColumnに指定された情報

プログラム実行例

デスクトップのファイル一覧

CONST ssfDESKTOP = 0

HASHTBL iColumn

DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDESKTOP)
DIM FolderItems = Folder.Items

FOR n = 0 TO 350
	iColumn[Folder.GetDetailsOf(EMPTYPARAM, n)] = n
NEXT

FOR n = 0 TO FolderItems.Count - 1
	DIM FolderItem = FolderItems.Item(n)
	WITH FolderItem
		PRINT .Name
		PRINT .Size + " Byte"
		PRINT .Type
	ENDWITH
	PRINT "-----"
NEXT

デフォルトプリンターを取得

CONST ssfPRINTERS = 4

DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfPRINTERS)
DIM FolderItems = Folder.Items

HASHTBL iColumn

FOR n = 0 TO 350
	iColumn[Folder.GetDetailsOf(EMPTYPARAM, n)] = n
NEXT

FOR n = 0 TO FolderItems.Count - 1
	DIM FolderItem = FolderItems.Item(n)
	DIM PrinterName = Folder.GetDetailsOf(FolderItem, iColumn["名前"])
	FOR i = 0 TO FolderItem.Verbs.Count - 1
		IF POS("通常使うプリンターに設定", FolderItem.Verbs.Item(i).Name) <> 0 THEN CONTINUE 2
	NEXT
	PRINT PrinterName
	BREAK
NEXT
結果
Brother DCP-J963N Printer

指定したフォルダの曲名と合計時間を出力

DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM Excel = CREATEOLEOBJ("Excel.Application")
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace("D:\Music\Hey! Say! JUMP\COSMIC☆HUMAN")
DIM serial

HASHTBL iColumn

FOR n = 0 TO 350
	iColumn[Folder.GetDetailsOf(EMPTYPARAM, n)] = n
NEXT

FOR n = 0 TO Folder.Items.Count - 1
	WITH Folder
		DIM FolderItem = .Items.Item(n)
		PRINT .GetDetailsOf(FolderItem, iColumn["名前"])
		serial = serial + timeValue(.GetDetailsOf(FolderItem, iColumn["長さ"]))
	ENDWITH
NEXT

PRINT "----------"
PRINT "合計時間<#TAB>" + text(serial, "h:m:s")

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

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

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

//////////////////////////////////////////////////
// 【引数】
//   時間 : 「hh:mm:ss」形式 
// 【戻値】
//   シリアル値 (例)0…00:00:00、0.5…12:00:00、1…24:00:00 
//////////////////////////////////////////////////
FUNCTION timeValue(str)
	HASHTBL Pattern
	Pattern["hour"] = "(1[0-9]|2[0-4]|0?[0-9])"
	Pattern["minute"] = "([1-5][0-9]|60|0?[0-9])"
	pattern["second"] = "([1-5][0-9]|60|0?[0-9])"
	SELECT TRUE
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"] + " (AM|PM)")
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"] + " (AM|PM)")
			WITH Matches.Item(0)
				SELECT .SubMatches(3)
					CASE "AM"
						time = (.SubMatches(0) / 24) + (.SubMatches(1) / 1440) + (.SubMatches(2) / 86400)
					CASE "PM"
						time = ((.SubMatches(0) + 12) / 24) + (.SubMatches(1) / 1440) + (.SubMatches(2) / 86400)
				SELEND
			ENDWITH
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"])
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"])
			WITH Matches.Item(0)
				time = (.SubMatches(0) / 24) + (.SubMatches(1) / 1440) + (.SubMatches(2) / 86400)
			ENDWITH
	SELEND
	RESULT = time
FEND

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

01 COSMIC☆HUMAN.wav
02 SWEET or HOT?.wav
03 ルーレット.wav
04 Draw My Life!.wav
05 COSMIC☆HUMAN (オリジナル・カラオケ).wav
06 SWEET or HOT- (オリジナル・カラオケ).wav
07 ルーレット (オリジナル・カラオケ).wav
08 Draw My Life! (オリジナル・カラオケ).wav
----------
合計時間 00:34:16

指定したフォルダの動画の合計時間を求める

DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace("D:\Videos\Apowersoft\Video Download Capture 6\Download\絶対零度")
DIM FolderItems = Folder.Items
DIM serial

HASHTBL iColumn

FOR n = 0 TO 350
	iColumn[Folder.GetDetailsOf(EMPTYPARAM, n)] = n
NEXT

FOR n = 0 TO FolderItems.Count - 1
	WITH Folder
		DIM FolderItem = .Items.Item(n)
		extension = .GetDetailsOf(FolderItem, iColumn["ファイル拡張子"])
		IFB FolderItem.IsFolder = FALSE THEN
			serial = serial + timeValue(.GetDetailsOf(FolderItem, iColumn["長さ"]))
		ENDIF
	ENDWITH
NEXT

PRINT text(serial, "hh:mm:ss")

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

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

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

//////////////////////////////////////////////////
// 【引数】
//   時間 : 「hh:mm:ss」形式 
// 【戻値】
//   シリアル値 (例)0…00:00:00、0.5…12:00:00、1…24:00:00 
//////////////////////////////////////////////////
FUNCTION timeValue(str)
	HASHTBL Pattern
	Pattern["hour"] = "(1[0-9]|2[0-4]|0?[0-9])"
	Pattern["minute"] = "([1-5][0-9]|60|0?[0-9])"
	pattern["second"] = "([1-5][0-9]|60|0?[0-9])"
	SELECT TRUE
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"] + " (AM|PM)")
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"] + " (AM|PM)")
			WITH Matches.Item(0)
				SELECT .SubMatches(3)
					CASE "AM"
						time = (.SubMatches(0) / 24) + (.SubMatches(1) / 1440) + (.SubMatches(2) / 86400)
					CASE "PM"
						time = ((.SubMatches(0) + 12) / 24) + (.SubMatches(1) / 1440) + (.SubMatches(2) / 86400)
				SELEND
			ENDWITH
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"])
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"])
			WITH Matches.Item(0)
				time = (.SubMatches(0) / 24) + (.SubMatches(1) / 1440) + (.SubMatches(2) / 86400)
			ENDWITH
	SELEND
	RESULT = time
FEND

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