本ページには広告が含まれています。
目次
- 1 定数一覧
- 2 vDirのパスを取得
- 3 CLSID
- 4 プログラム実行例
- 4.1 指定したファイルを削除する確認メッセージを表示
- 4.2 指定したファイルを開く
- 4.3 エクスプローラーで指定したフォルダを開く
- 4.4 デスクトップを開く
- 4.5 プロパティの項目を取得
- 4.6 デスクトップのファイル一覧
- 4.7 フォルダ内のファイルを更新日時でソートする
- 4.8 写真を撮影日時毎にフォルダ分けする
- 4.9 全ファイルをサブフォルダから直下に取り出す
- 4.10 フォルダ内の音声ファイルをすべて再生
- 4.11 指定したファイルをゴミ箱に移動する
- 4.12 デスクトップのパスを取得
- 4.13 デスクトップにあるアイテムの数
- 4.14 右クリックメニュー取得
- 4.15 指定フォルダ内の拡張子をすべて小文字にする
- 4.16 UWSC.INIのDefaultFontを変更する
- 4.17 デフォルトプリンターを取得
- 4.18 歌ネットから歌詞を取得してテキストファイルに保存
- 4.19 指定したファイルがショートカットかを取得
- 4.20 指定したフォルダの曲名と合計時間を出力
- 4.21 指定したフォルダの動画の合計時間を求める
- 4.22 コマンドプロンプトのショートカットを生成
- 4.23 デスクトップにChromeのショートカットを作成
- 4.24 デスクトップにあるフォルダ一覧を取得
- 4.25 ファイルシステムかどうか
- 5 参考文献
指定されたフォルダーのFolder2 オブジェクトを作成して返します。
- 構文
- Folder2 = Shell.NameSpace( vDir )
- 引数
- vDir 必須
- フォルダーのパスもしくはShellSpecialFolderConstants 列挙を指定
- 戻り値
- 指定されたフォルダーのFolder2 オブジェクト
定数一覧
ShellSpecialFolderConstants 列挙
名前 | 値 | 説明 |
---|---|---|
ssfDESKTOP | 0 | デスクトップ |
ssfPROGRAMS | 2 | プログラム C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs |
ssfCONTROLS | 3 | すべてのコントロール パネル項目 |
ssfPRINTERS | 4 | プリンター |
ssfPERSONAL | 5 | ドキュメント |
ssfFAVORITES | 6 | お気に入り |
ssfSTARTUP | 7 | スタートアップ C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup |
ssfRECENT | 8 | 最近使った項目 |
ssfSENDTO | 9 | 送る C:\Users\username\AppData\Roaming\Microsoft\Windows\SendTo |
ssfBITBUCKET | 10 | ごみ箱 |
ssfSTARTMENU | 11 | スタート メニュー |
ssfDESKTOPDIRECTORY | 16 | デスクトップ C:\Documents and Settings\username\Desktop |
ssfDRIVES | 17 | PC |
ssfNETWORK | 18 | ネットワーク |
ssfNETHOOD | 19 | Network Shortcuts C:\Users\username\AppData\Roaming\Microsoft\Windows\Network Shortcuts |
ssfFONTS | 20 | フォント C:\Windows\Fonts |
ssfTEMPLATES | 21 | Templates C:\Users\username\AppData\Roaming\Microsoft\Windows\Templates |
ssfCOMMONSTARTMENU | 22 | スタート メニュー C:\ProgramData\Microsoft\Windows\Start Menu |
ssfCOMMONPROGRAMS | 23 | プログラム C:\ProgramData\Microsoft\Windows\Start Menu\Programs |
ssfCOMMONSTARTUP | 24 | スタートアップ(全ユーザー共通) C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp |
ssfCOMMONDESKTOPDIR | 25 | パブリックデスクトップ C:\Users\Public\Desktop |
ssfAPPDATA | 26 | Roaming C:\Users\username\AppData\Roaming |
ssfPRINTHOOD | 27 | C:\Users\username\AppData\Roaming\Microsoft\Windows\Printer Shortcuts |
ssfLOCALAPPDATA | 28 | Local C:\Users\username\AppData\Local |
ssfALTSTARTUP | 29 | スタートアップ(ログオンユーザー) C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup |
ssfCOMMONALTSTARTUP | 30 | スタートアップ(全ユーザー共通) C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp |
ssfCOMMONFAVORITES | 31 | お気に入り C:\Users\username\Favorites |
ssfINTERNETCACHE | 32 | Temporary Internet Files |
ssfCOOKIES | 33 | INetCookies |
ssfHISTORY | 34 | History |
ssfCOMMONAPPDATA | 35 | C:\ProgramData |
ssfWINDOWS | 36 | %windir% or %SystemRoot% |
ssfSYSTEM | 37 | C:\Windows\System32 |
ssfPROGRAMFILES | 38 | C:\Program Files (x86) |
ssfMYPICTURES | 39 | ピクチャ |
ssfPROFILE | 40 | C:\Users\username |
ssfSYSTEMx86 | 41 | C:\WindowsSystem32 C:\WindowsSyswow32 |
ssfPROGRAMFILESx86 | 48 | C:\Program Files C:\Program Files (X86) |
CONST ssfDESKTOP = 0
CONST ssfPROGRAMS = 2
CONST ssfCONTROLS = 3
CONST ssfPRINTERS = 4
CONST ssfPERSONAL = 5
CONST ssfFAVORITES = 6
CONST ssfSTARTUP = 7
CONST ssfRECENT = 8
CONST ssfSENDTO = 9
CONST ssfBITBUCKET = 10
CONST ssfSTARTMENU = 11
CONST ssfDESKTOPDIRECTORY = 16
CONST ssfDRIVES = 17
CONST ssfNETWORK = 18
CONST ssfNETHOOD = 19
CONST ssfFONTS = 20
CONST ssfTEMPLATES = 21
CONST ssfCOMMONSTARTMENU = 22
CONST ssfCOMMONPROGRAMS = 23
CONST ssfCOMMONSTARTUP = 24
CONST ssfCOMMONDESKTOPDIR = 25
CONST ssfAPPDATA = 26
CONST ssfPRINTHOOD = 27
CONST ssfLOCALAPPDATA = 28
CONST ssfALTSTARTUP = 29
CONST ssfCOMMONALTSTARTUP = 30
CONST ssfCOMMONFAVORITES = 31
CONST ssfINTERNETCACHE = 32
CONST ssfCOOKIES = 33
CONST ssfHISTORY = 34
CONST ssfCOMMONAPPDATA = 35
CONST ssfWINDOWS = 36
CONST ssfSYSTEM = 37
CONST ssfPROGRAMFILES = 38
CONST ssfMYPICTURES = 39
CONST ssfPROFILE = 40
CONST ssfSYSTEMx86 = 41
CONST ssfPROGRAMFILESx86 = 48
vDirのパスを取得
vDirの値と取得されるフォルダのパスのリストです。
PRINT Shell.NameSpace(vDir).Self.Path
vDir | パス |
---|---|
0 | C:\Users\username\Desktop |
1 | ::{871C5380-42A0-1069-A2EA-08002B30309D} |
2 | C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs |
3 | ::{26EE0668-A00A-44D7-9371-BEB064C98683}\0 |
4 | ::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{2227A280-3AEA-1069-A2DE-08002B30309D} |
5 | C:\Users\username\Documents |
6 | C:\Users\username\Favorites |
7 | C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup |
8 | C:\Users\username\AppData\Roaming\Microsoft\Windows\Recent |
9 | C:\Users\username\AppData\Roaming\Microsoft\Windows\SendTo |
10 | ::{645FF040-5081-101B-9F08-00AA002F954E} |
11 | C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu |
13 | C:\Users\username\Music |
14 | C:\Users\username\Videos |
17 | ::{20D04FE0-3AEA-1069-A2D8-08002B30309D} |
18 | ::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C} |
19 | C:\Users\username\AppData\Roaming\Microsoft\Windows\Network Shortcuts |
20 | C:\Windows\Fonts |
21 | C:\Users\username\AppData\Roaming\Microsoft\Windows\Templates |
22 | C:\ProgramData\Microsoft\Windows\Start Menu |
23 | C:\ProgramData\Microsoft\Windows\Start Menu\Programs |
24 | C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp |
25 | C:\Users\Public\Desktop |
26 | C:\Users\username\AppData\Roaming |
27 | C:\Users\username\AppData\Roaming\Microsoft\Windows\Printer Shortcuts |
28 | C:\Users\username\AppData\Local |
32 | C:\Users\username\AppData\Local\Microsoft\Windows\INetCache |
33 | C:\Users\username\AppData\Local\Microsoft\Windows\INetCookies |
34 | C:\Users\username\AppData\Local\Microsoft\Windows\History |
35 | C:\ProgramData |
36 | C:\Windows |
37 | C:\Windows\System32 |
38 | C:\Program Files |
39 | C:\Users\username\Pictures |
40 | C:\Users\username |
43 | C:\Program Files\Common Files |
45 | C:\ProgramData\Microsoft\Windows\Templates |
46 | C:\Users\Public\Documents |
47 | C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools |
48 | C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Administrative Tools |
49 | ::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{7007ACC7-3202-11D1-AAD2-00805FC1270E} |
53 | C:\Users\Public\Music |
54 | C:\Users\Public\Pictures |
55 | C:\Users\Public\Videos |
56 | C:\Windows\Resources |
57 | C:\Windows\Resources\0411 |
58 | C:\ProgramData\OEM Links |
59 | C:\Users\username\AppData\Local\Microsoft\Windows\Burn\Burn |
CLSID
「ファイル名を指定して実行」で以下を実行すると対応するアプリが起動します。
explorer shell:{CLSID}
アプリ名 | CLSID |
---|---|
Internet Explorer | ::{871C5380-42A0-1069-A2EA-08002B30309D} |
コントロールパネル(カテゴリ) | ::{26EE0668-A00A-44D7-9371-BEB064C98683} |
コントロールパネル\すべてのコントロールパネル項目(小さいアイコン) | ::{26EE0668-A00A-44D7-9371-BEB064C98683}\0 |
すべてのコントロールパネル項目 | ::{21EC2020-3AEA-1069-A2DD-08002B30309D} |
PC | ::{20D04FE0-3AEA-1069-A2D8-08002B30309D} |
ネットワーク | ::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C} |
すべてのコントロールパネル項目 | ::{21EC2020-3AEA-1069-A2DD-08002B30309D} |
すべてのコントロールパネル項目\ネットワーク | ::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{7007ACC7-3202-11D1-AAD2-00805FC1270E} |
プログラム実行例
指定したファイルを削除する確認メッセージを表示
CONST ssfDesktop = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDesktop)
DIM FolderItem = Folder.ParseName("D:\Desktop\sample.txt")
FolderItem.InvokeVerb("delete")
使用関数
指定したファイルを開く
CONST ssfDesktop = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDesktop)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM path = "D:\Desktop\sample.txt"
IF FSO.FileExists(path) = FALSE THEN EXIT
DIM FolderItem = Folder.ParseName(path)
FolderItem.InvokeVerb()
使用関数
エクスプローラーで指定したフォルダを開く
CONST ssfDESKTOP = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DOSCMD("explorer <#DBL>" + Shell.NameSpace(ssfDESKTOP).Self.Path + "<#DBL>")
使用関数
デスクトップを開く
CONST ssfDESKTOP = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDESKTOP)
DIM FolderItemVerbs = Folder.Self.Verbs()
FOR FolderItemVerb IN FolderItemVerbs
IF POS("&O", FolderItemVerb.Name) <> 0 THEN FolderItemVerb.DoIt()
NEXT
使用関数
プロパティの項目を取得
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM path = "C:\Users\akita\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Internet Explorer.lnk"
DIM Folder = Shell.NameSpace(FSO.GetParentFolderName(path))
HASHTBL iColumn
FOR i = 0 TO 350
iColumn[Folder.GetDetailsOf(EMPTYPARAM, i)] = i
NEXT
FOR i = 0 TO LENGTH(iColumn)
iColumn[iColumn[i, HASH_VAL]] = iColumn[i, HASH_KEY]
NEXT
DIM FolderItem = Folder.ParseName(FSO.GetFileName(path))
DIM array[] = "名前", "項目の種類", "ファイルの説明", "フォルダーのパス", "サイズ", "作成日時", "更新日時", "アクセス日時", "属性"
FOR i = 0 TO UBound(array)
PRINT array[i] + ","+ Folder.GetDetailsOf(FolderItem, iColumn[array[i]])
NEXT
//////////////////////////////////////////////////
// 【引数】
// inputs : 繰り返す文字列
// multiplier : inputsを繰り返す回数
// 【戻り値】
// inputsをmultiplier回を繰り返した文字列を返します
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
DIM res = ""
FOR n = 1 TO multiplier
res = res + inputs
NEXT
RESULT = res
FEND
//////////////////////////////////////////////////
// 【引数】
// arrayname : 上限値を求める配列の名前
// dimension : 返す次元を示す整数
// 【戻り値】
// 配列の上限値
//////////////////////////////////////////////////
FUNCTION UBound(arrayname[], dimension = 1)
RESULT = EVAL("RESIZE(arrayname" + strRepeat("[0]", dimension - 1) + ")")
FEND
結果
名前, Internet Explorer
項目の種類, ショートカット
ファイルの説明,
フォルダーのパス, C:\ユーザー\akita\AppData\Roaming\Microsoft\Windows\スタート メニュー\プログラム\Windows アクセサリ
サイズ, 1.31 KB
作成日時, 2021/02/04 12:46
更新日時, 2022/05/18 02:24
アクセス日時, 2023/04/24 00:29
属性, A
使用関数
解説
デスクトップのファイル一覧
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
使用関数
解説
フォルダ内のファイルを更新日時でソートする
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace("C:\Program Files (x86)\UWSC")
DIM FolderItems = Folder.Items
HASHTBL iColumn
FOR i = 0 TO 350
iColumn[Folder.GetDetailsOf(EMPTYPARAM, i)] = i
NEXT
DIM filename[-1]
DIM datetime[-1]
FOR i = 0 TO FolderItems.Count - 1
DIM FolderItem = FolderItems.Item(i)
IF FolderItem.isFolder THEN CONTINUE
arrayPush(filename, Folder.GetDetailsOf(FolderItem,iColumn["名前"]))
arrayPush(datetime, Folder.GetDetailsOf(FolderItem, iColumn["更新日時"]))
NEXT
QSORT(datetime, QSRT_NATURALA, filename)
FOR i = 0 TO UBound(filename)
PRINT filename[i] + "<#TAB>" + datetime[i]
NEXT
//////////////////////////////////////////////////
// 【引数】
// array : 要素を追加する配列(参照引数)
// values : 追加する要素をvalue1から指定
// 【戻り値】
// 処理後の配列の要素の数
//////////////////////////////////////////////////
FUNCTION arrayPush(var array[], value1 = EMPTY, value2 = EMPTY, value3 = EMPTY, value4 = EMPTY, value5 = EMPTY, value6 = EMPTY, value7 = EMPTY, value8 = EMPTY, value9 = EMPTY, value10 = EMPTY, value11 = EMPTY, value12 = EMPTY, value13 = EMPTY, value14 = EMPTY, value15 = EMPTY, value16 = EMPTY)
DIM i = 1
WHILE EVAL("value" + i) <> EMPTY
DIM res = RESIZE(array, UBound(array) + 1)
array[res] = EVAL("value" + i)
i = i + 1
WEND
RESULT = LENGTH(array)
FEND
//////////////////////////////////////////////////
// 【引数】
// inputs : 繰り返す文字列
// multiplier : inputsを繰り返す回数
// 【戻り値】
// inputsをmultiplier回を繰り返した文字列を返します
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
DIM res = ""
FOR n = 1 TO multiplier
res = res + inputs
NEXT
RESULT = res
FEND
//////////////////////////////////////////////////
// 【引数】
// arrayname : 上限値を求める配列の名前
// dimension : 返す次元を示す整数
// 【戻り値】
// 配列の上限値
//////////////////////////////////////////////////
FUNCTION UBound(arrayname[], dimension = 1)
RESULT = EVAL("RESIZE(arrayname" + strRepeat("[0]", dimension - 1) + ")")
FEND
結果
UDebug.chm 2014/05/11 1:58
RecIE.chm 2014/05/11 1:58
Uws2Exe.chm 2015/08/13 16:12
RecUws.dll 2016/03/25 4:57
UWSC.exe 2016/10/15 13:33
Uws2Exe.exe 2016/10/15 13:34
RecIE.exe 2016/10/15 13:35
UDebug.exe 2016/10/15 13:37
XRef.exe 2016/10/15 13:38
Readme.txt 2016/10/15 13:39
uwsc.chm 2016/10/15 13:41
unins000.exe 2018/06/27 12:48
unins000.dat 2018/06/27 12:49
使用関数
写真を撮影日時毎にフォルダ分けする
CONST ssfMYPICTURES = 39
DIM Folder[1]
DIM folderspec[1]
DIM Shell = CREATEOLEOBJ("Shell.Application")
folderspec[0] = "D:\Pictures\100ANDRO\"
Folder[0] = Shell.NameSpace(folderspec[0])
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
HASHTBL iColumn
FOR i = 0 TO 350
iColumn[Folder[0].GetDetailsOf(EMPTYPARAM, i)] = i
NEXT
DIM destination[-1]
DIM path[-1]
DIM cnt = Folder[0].Items.Count - 1
FOR i = cnt TO 0 STEP -1
FUKIDASI(i + "/" + cnt)
DIM FolderItem = Folder[0].Items.Item(i)
IF FolderItem.isFolder THEN CONTINUE
DIM filename = FolderItem.Name
DIM datetime = deleteControlCharacter(Folder[0].GetDetailsOf(FolderItem, iColumn["撮影日時"]))
PRINT filename
PRINT datetime
PRINT "-----"
TRY
DIM date = text(dateValue(datetime), "yyyy-mm-dd")
EXCEPT
date = "0000-00-00"
ENDTRY
folderspec[1] = FSO.BuildPath(folderspec[0], date)
Folder[1] = Shell.NameSpace(folderspec[1])
arrayPush(destination, folderspec[1])
arrayPush(path, FolderItem.Path)
NEXT
FOR i = 0 TO UBound(destination)
IF !FSO.FolderExists(destination[i]) THEN CreateFolders(destination[i])
Folders = Shell.NameSpace(destination[i])
Folders.MoveHere(path[i])
NEXT
FUNCTION deleteControlCharacter(str)
DIM array[] = CHR(8206), CHR(8207)
FOR item IN array
str = REPLACE(str, item, "")
NEXT
RESULT = str
FEND
//////////////////////////////////////////////////
// 【引数】
// array : 要素を追加する配列(参照引数)
// values : 追加する要素をvalue1から指定
// 【戻り値】
// 処理後の配列の要素の数
//////////////////////////////////////////////////
FUNCTION arrayPush(var array[], value1 = EMPTY, value2 = EMPTY, value3 = EMPTY, value4 = EMPTY, value5 = EMPTY, value6 = EMPTY, value7 = EMPTY, value8 = EMPTY, value9 = EMPTY, value10 = EMPTY, value11 = EMPTY, value12 = EMPTY, value13 = EMPTY, value14 = EMPTY, value15 = EMPTY, value16 = EMPTY)
DIM i = 1
WHILE EVAL("value" + i) <> EMPTY
DIM res = RESIZE(array, UBound(array) + 1)
array[res] = EVAL("value" + i)
i = i + 1
WEND
RESULT = LENGTH(array)
FEND
//////////////////////////////////////////////////
// 【引数】
// needle : 検索する値
// haystack : 配列
// 【戻り値】
// needleが見つかった場合に配列のキー
//////////////////////////////////////////////////
FUNCTION arraySearch(needle, haystack[])
DIM i = 0
FOR item IN haystack
IFB item = needle THEN
RESULT = i
EXIT
ENDIF
i = i + 1
NEXT
FEND
//////////////////////////////////////////////////
// 【引数】
// folderspec : 作成するフォルダのパス
// 【戻り値】
//
//////////////////////////////////////////////////
PROCEDURE CreateFolders(folderspec)
WITH CREATEOLEOBJ("Scripting.FileSystemObject")
folderspec = .GetAbsolutePathName(folderspec)
IF !.DriveExists(.GetDriveName(folderspec)) THEN EXIT
DIM parentPath = .GetParentFolderName(folderspec)
IF !.FolderExists(parentPath) THEN CreateFolders(parentPath)
IF !.FolderExists(folderspec) THEN .CreateFolder(folderspec)
ENDWITH
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)
DIM time = G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
SELECT interval
CASE "yyyy"
d = (G_TIME_YY + num) + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
IF time <> "00:00:00" THEN d = d + " " + time
CASE "m"
IFB num > 0 THEN
year = G_TIME_YY + INT((G_TIME_MM + num) / 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
IF time <> "00:00:00" THEN d = d + " " + time
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
//////////////////////////////////////////////////
// 【引数】
// str : 日付文字列
// 【戻り値】
// シリアル値
//////////////////////////////////////////////////
FUNCTION dateValue(str)
CONST cutOffYear = 2049
DIM Months[] = "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
HASHTBL Pattern
Pattern["year"] = "(19[0-9]{2}|[2-9][0-9]{3})"
Pattern["year2"] = "([0-9]{2})"
Pattern["era"] = "(明治?|大正?|昭和?|平成?|令和?|[MTSHR])(元|\d+)"
Pattern["month"] = "(1[0-2]|0?[1-9])"
Pattern["month2"] = "(0[1-9]|1[0-2])"
Pattern["month_en"] = "(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Sept|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)"
Pattern["day"] = "([1-2][0-9]|3[0-1]|0?[1-9])"
Pattern["day2"] = "(0[1-9]|[1-2][0-9]|3[0-1])"
Pattern["day_en"] = "(1(?:st)|2?2(?:nd)|2?3(?:rd)|[1-3]?[04-9](?:th)|1[1-3](?:th)|[1-3]1(?:st))"
Pattern["separator"] = "([./\-])"
HASHTBL era
era["明治"] = 1867; era["明"] = 1867; era["M"] = 1867;
era["大正"] = 1911; era["大"] = 1911; era["T"] = 1911;
era["昭和"] = 1925; era["昭"] = 1925; era["S"] = 1925;
era["平成"] = 1988; era["平"] = 1988; era["H"] = 1988;
era["令和"] = 2018; era["令"] = 2018; era["R"] = 2018;
SELECT TRUE
CASE reTest(str, "\b" + Pattern["year"] + Pattern["separator"] + Pattern["month"] + "(?:\2" + Pattern["day"] + ")?\b")
Matches = reExecute(str, "\b(?:" + Pattern["year"] + Pattern["separator"] + ")?" + Pattern["month"] + "(?:\2" + Pattern["day"] + ")?\b")
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + text(.SubMatches(2), "00") + "/" + text(IIF(.SubMatches(3)="", "01", .SubMatches(3)), "00")
ENDWITH
CASE reTest(str, "\b" + Pattern["month"] + Pattern["separator"] + Pattern["day"] + "(?:\2" + Pattern["year"] + ")?\b")
Matches = reExecute(str, "\b" + Pattern["month"] + Pattern["separator"] + Pattern["day"] + "(?:\2" + Pattern["year"] + ")?\b")
WITH Matches.Item(0)
date = .SubMatches(3) + "/" + text(.SubMatches(0), "00") + "/" + text(.SubMatches(2), "00")
ENDWITH
CASE reTest(str, "\b" + Pattern["day"] + Pattern["separator"] + Pattern["month"] + "\2" + Pattern["year"] + "\b")
Matches = reExecute(str, "\b" + Pattern["day"] + Pattern["separator"] + Pattern["month"] + "\2" + Pattern["year"] + "\b")
WITH Matches.Item(0)
date = .SubMatches(3) + "/" + text(.SubMatches(2), "00") + "/" + text(.SubMatches(0), "00")
ENDWITH
CASE reTest(str, Pattern["era"] + Pattern["separator"] + Pattern["month"] + "(?:\3" + Pattern["day"] + ")?")
Matches = reExecute(str, Pattern["era"] + Pattern["separator"] + Pattern["month"] + "(?:\3" + Pattern["day"] + ")?")
WITH Matches.Item(0)
date = (era[.SubMatches(0)] + VAL(.SubMatches(1))) + "/" + text(.SubMatches(3), "00") + "/" + IIF(.SubMatches(4)="", "01", text(.SubMatches(4), "00"))
ENDWITH
CASE reTest(str, "\b" + Pattern["year2"] + Pattern["separator"] + Pattern["month"] + "\2" + Pattern["day"] + "\b")
Matches = reExecute(str, "\b" + Pattern["year2"] + Pattern["separator"] + Pattern["month"] + "\2" + Pattern["day"] + "\b")
WITH Matches.Item(0)
y = VAL(.SubMatches(0))
date = (IIF(y <= cutOffYear MOD 100, INT(cutOffYear/100) * 100, INT(cutOffYear/100) * 100 - 100) + y) + "/" + text(.SubMatches(2), "00") + "/" + text(.SubMatches(3), "00")
ENDWITH
CASE reTest(str, "\b" + Pattern["month"] + Pattern["separator"] + Pattern["day"] + "\2" + Pattern["year2"] + "\b")
Matches = reExecute(str, "\b" + Pattern["month"] + Pattern["separator"] + Pattern["day"] + "\2" + Pattern["year2"] + "\b")
WITH Matches.Item(0)
y = VAL(.SubMatches(3))
date = (IIF(y <= cutOffYear MOD 100, INT(cutOffYear/100) * 100, INT(cutOffYear/100) * 100 - 100) + y) + "/" + text(.SubMatches(0), "00") + "/" + text(.SubMatches(2), "00")
ENDWITH
CASE reTest(str, "\b" + Pattern["day"] + Pattern["separator"] + Pattern["month"] + "\2" + Pattern["year2"] + "\b")
Matches = reExecute(str, "\b" + Pattern["day"] + Pattern["separator"] + Pattern["month"] + "\2" + Pattern["year2"] + "\b")
WITH Matches.Item(0)
y = VAL(.SubMatches(3))
date = (IIF(y <= cutOffYear MOD 100, INT(cutOffYear/100) * 100, INT(cutOffYear/100) * 100 - 100) + y) + "/" + text(.SubMatches(2), "00") + "/" + text(.SubMatches(0), "00")
ENDWITH
CASE reTest(str, "\b" + Pattern["month_en"] + " " + Pattern["day_en"] + ",\s*" + Pattern["year"] + "\b")
Matches = reExecute(str, "\b" + Pattern["month_en"] + " " + Pattern["day_en"] + ",\s*" + Pattern["year"] + "\b")
WITH Matches.Item(0)
date = .SubMatches(2) + "/" + text(VAL(arraySearch(COPY(.SubMatches(0), 1, 3), Months)) + 1, "00") + "/" + REPLACE(REPLACE(REPLACE(REPLACE(.SubMatches(1), "st", ""), "nd", ""), "rd", ""), "th", "")
ENDWITH
CASE reTest(str, "\b" + Pattern["day_en"] + " " + Pattern["month_en"] + " " + Pattern["year"] + "\b")
Matches = reExecute(str, "\b" + Pattern["day_en"] + " " + Pattern["month_en"] + " " + Pattern["year"] + "\b")
WITH Matches.Item(0)
date = .SubMatches(2) + "/" + text(VAL(arraySearch(COPY(.SubMatches(1), 1, 3), Months)) + 1, "00") + "/" + REPLACE(REPLACE(REPLACE(REPLACE(.SubMatches(0), "st", ""), "nd", ""), "rd", ""), "th", "")
ENDWITH
CASE reTest(str, Pattern["era"] + "年" + Pattern["month"] + "月(?:" + Pattern["day"] + "日)?")
Matches = reExecute(str, Pattern["era"] + "年" + Pattern["month"] + "月(?:" + Pattern["day"] + "日)?")
WITH Matches.Item(0)
date = era[.SubMatches(0)] + VAL(.SubMatches(1)) + "/" + text(.SubMatches(2), "00") + "/" + IIF(.SubMatches(3)="", "01", text(.SubMatches(3), "00"))
ENDWITH
CASE reTest(str, "\b" + Pattern["year"] + "年" + Pattern["month"] + "月(?:" + Pattern["day"] + "日)?")
Matches = reExecute(str, "\b" + Pattern["year"] + "年" + Pattern["month"] + "月(?:" + Pattern["day"] + "日)?")
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + text(.SubMatches(1), "00") + "/" + IIF(.SubMatches(2)="", "01", text(.SubMatches(2), "00"))
ENDWITH
CASE reTest(str, "\b" + Pattern["month"] + "月" + Pattern["day"] + "日")
Matches = reExecute(str, "\b" + Pattern["month"] + "月" + Pattern["day"] + "日")
WITH Matches.Item(0)
date = getYear(today()) + "/" + text(.SubMatches(0), "00") + "/" + text(.SubMatches(1), "00")
ENDWITH
CASE LENGTH(str) = 6 AND reTest(str, Pattern["year2"] + Pattern["month2"] + Pattern["day2"])
Matches = reExecute(str, Pattern["year2"] + Pattern["month2"] + Pattern["day2"])
WITH Matches.Item(0)
y = VAL(.SubMatches(0))
date = (IIF(y <= cutOffYear MOD 100, INT(cutOffYear/100) * 100, INT(cutOffYear/100) * 100 - 100) + y) + "/" + .SubMatches(1) + "/" + .SubMatches(2)
ENDWITH
CASE LENGTH(str) = 6 AND reTest(str, Pattern["month2"] + Pattern["day2"] + Pattern["year2"])
Matches = reExecute(str, Pattern["month2"] + Pattern["day2"] + Pattern["year2"])
WITH Matches.Item(0)
y = VAL(.SubMatches(2))
date = (IIF(y <= cutOffYear MOD 100, INT(cutOffYear/100) * 100, INT(cutOffYear/100) * 100 - 100) + y) + "/" + .SubMatches(0) + "/" + .SubMatches(1)
ENDWITH
CASE LENGTH(str) = 6 AND reTest(str, Pattern["day2"] + Pattern["month2"] + Pattern["year2"])
Matches = reExecute(str, Pattern["day2"] + Pattern["month2"] + Pattern["year2"])
WITH Matches.Item(0)
y = VAL(.SubMatches(2))
date = (IIF(y <= cutOffYear MOD 100, INT(cutOffYear/100) * 100, INT(cutOffYear/100) * 100 - 100) + y) + "/" + .SubMatches(1) + "/" + .SubMatches(0)
ENDWITH
CASE reTest(str, "\b" + Pattern["year"] + Pattern["month"] + Pattern["day"] + "\b")
Matches = reExecute(str, "\b" + Pattern["year"] + Pattern["month"] + Pattern["day"] + "\b")
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + .SubMatches(1) + "/" + .SubMatches(2)
ENDWITH
CASE reTest(str, "\b" + Pattern["month"] + Pattern["day"] + Pattern["year"] + "\b")
Matches = reExecute(str, "\b" + Pattern["month"] + Pattern["day"] + Pattern["year"] + "\b")
WITH Matches.Item(0)
date = .SubMatches(2) + "/" + .SubMatches(0) + "/" + .SubMatches(1)
ENDWITH
CASE reTest(str, "\b" + Pattern["day"] + Pattern["month"] + Pattern["year"] + "\b")
Matches = reExecute(str, "\b" + Pattern["day"] + Pattern["month"] + Pattern["year"] + "\b")
WITH Matches.Item(0)
date = .SubMatches(2) + "/" + .SubMatches(1) + "/" + .SubMatches(0)
ENDWITH
DEFAULT
RESULT = ERR_VALUE
EXIT
SELEND
RESULT = uwscToSerial(GETTIME(0, date))
FEND
//////////////////////////////////////////////////
// 【引数】
// array : 最大公約数を求める数値を格納した配列
// 【戻り値】
// 最大公約数
//////////////////////////////////////////////////
FUNCTION GCD(array[])
DIM c = LENGTH(array)
DIM rem = array[c-1] MOD array[c-2]
IFB rem = 0 THEN
IFB LENGTH(array) = 2 THEN
RESULT = array[c-2]
EXIT
ENDIF
RESIZE(array, c-2)
RESULT = GCD(array)
EXIT
ENDIF
array[c-1] = array[c-2]
array[c-2] = rem
RESULT = GCD(array)
FEND
//////////////////////////////////////////////////
// 【引数】
// date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”)
// m : 第一引数の指定日からプラスマイナスm月とする
// 【戻り値】
// 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
//////////////////////////////////////////////////
// 【引数】
// date : 日付文字列(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”)もしくはシリアル値
// type : 取得する曜日番号の種類を示す0〜3または11〜17の値。1と17は日曜日を1、2と11は月曜日を1とカウントします。11以降はExcel2010で追加された値で、互換性を保つために重複した値があります。
// 【戻り値】
// typeで指定した種類によって以下の値を返します。 : (0 : 0(日曜)〜6(土曜)、1 : 1(日曜)~7(土曜)、2 : 1(月曜)~7(日曜)、3 : 0(月曜)〜6(日曜)、11 : 1(月曜)~7(日曜)、12 : 1(火曜)~7(月曜)、13 : 1(水曜)~7(火曜)、14 : 1(木曜)~7(水曜)、15 : 1(金曜)~7(木曜)、16 : 1(土曜)~7(金曜)、17 : 1(日曜)~7(土曜))
//////////////////////////////////////////////////
FUNCTION getWeekday(date, type = 1)
IF VARTYPE(date) <> 258 THEN date = text(date, "yyyy/mm/dd")
GETTIME(0, date)
DIM w = G_TIME_WW
SELECT TRUE
CASE type = 0
RESULT = w
CASE type = 1
RESULT = w + 1
CASE type = 2
RESULT = IIF(w=0, 7, w)
CASE type = 3
RESULT = (w+6) MOD 7
CASE type >= 11
RESULT = ((getWeekday(date, 2) + 17 - type) MOD 7) + 1
SELEND
FEND
//////////////////////////////////////////////////
// 【引数】
// date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”)
// 【戻り値】
// 指定した日付の「年」
//////////////////////////////////////////////////
FUNCTION getYear(date)
GETTIME(0, date)
RESULT = G_TIME_YY4
FEND
//////////////////////////////////////////////////
// 【引数】
// serial : シリアル値もしくは時刻文字列
// 【戻り値】
// 時刻から時間を表す0〜23の範囲の値
//////////////////////////////////////////////////
FUNCTION Hour(serial)
IF VARTYPE(serial) = 258 THEN serial = timeValue(serial)
RESULT = INT(serial * 24) MOD 24
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
//////////////////////////////////////////////////
// 【引数】
// date : 存在するかを調べる日付文字列。YYYYMMDD or YYYY/MM/DD or YYYY-MM-DDのいずれかの形式。
// 【戻り値】
// TRUE : 日付として認識できる、FALSE : 日付として認識できない
//////////////////////////////////////////////////
FUNCTION isDate(date)
TRY
GETTIME(0, date)
RESULT = TRUE
EXCEPT
RESULT = FALSE
ENDTRY
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
//////////////////////////////////////////////////
// 【引数】
// 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 : フォーマット
// 【戻り値】
// 数値を表示書式に基づいて変換した文字列
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// 【引数】
// 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"
serial = VAL(serial)
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)
DIM aaa[] = "日", "月", "火", "水", "木", "金", "土"
DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"
DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
RESULT = EVAL(Matches.Item(0).SubMatches(0) + "[" + getWeekday(G_TIME_WW, 1) + "]")
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, ".")) <= 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
//////////////////////////////////////////////////
// 【引数】
// str : 時刻文字列。hh:nn:ss AM/PM、hh:nn AM/PM、hh AM/PM、hh:nn:ss、hh:nn、hh時nn分ss秒、hh時nn分のいずれかの形式を指定。
// 【戻り値】
// シリアル値 (例)0…00:00:00、0.5…12:00:00、0.999988425925926…23:59:59
//////////////////////////////////////////////////
FUNCTION timeValue(str)
DIM serial = 0
DIM Matches
DIM pattern = "(\d+)"
DIM hh = "(0?[0-9]|1[0-2])"
DIM ampm = "([AP]M|[ap]m)"
SELECT TRUE
CASE reTest(str, "\b" + hh + ":" + pattern + ":" + pattern + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + ":" + pattern + ":" + pattern + " " + ampm + "\b")
WITH Matches.Item(0)
serial = timeValue(.SubMatches(0) + " " + .SubMatches(3)) + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + hh + ":" + pattern + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + ":" + pattern + " " + ampm + "\b")
WITH Matches.Item(0)
serial = timeValue(.SubMatches(0) + " " + .SubMatches(2)) + VAL(.SubMatches(1)) / 1440
ENDWITH
CASE reTest(str, "\b" + hh + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + " " + ampm + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0) MOD 12) + IIF(reTest(.SubMatches(1), "AM|am"), 0, 12)
serial = serial / 24
ENDWITH
CASE reTest(str, "\b" + pattern + ":" + pattern + ":" + pattern + "\b")
Matches = reExecute(str, "\b" + pattern + ":" + pattern + ":" + pattern + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + pattern + ":" + pattern + "\b")
Matches = reExecute(str, "\b" + pattern + ":" + pattern + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440
ENDWITH
CASE reTest(str, "\b" + pattern + "時" + pattern + "分" + pattern + "秒")
Matches = reExecute(str, "\b" + pattern + "時" + pattern + "分" + pattern + "秒")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + pattern + "時" + pattern + "分")
Matches = reExecute(str, "\b" + pattern + "時" + pattern + "分")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440
ENDWITH
DEFAULT
serial = ERR_VALUE
SELEND
RESULT = serial - INT(serial)
FEND
//////////////////////////////////////////////////
// 【引数】
//
// 【戻り値】
//
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// 【引数】
// arrayname : 上限値を求める配列の名前
// dimension : 返す次元を示す整数
// 【戻り値】
// 配列の上限値
//////////////////////////////////////////////////
FUNCTION UBound(arrayname[], dimension = 1)
RESULT = EVAL("RESIZE(arrayname" + strRepeat("[0]", dimension - 1) + ")")
FEND
//////////////////////////////////////////////////
// 【引数】
// uwscTime : UWSC時間
// 【戻り値】
// シリアル値
//////////////////////////////////////////////////
FUNCTION uwscToSerial(uwscTime)
uwscDate = uwscTime / 86400
RESULT = 36526 + uwscDate
FEND
使用関数
全ファイルをサブフォルダから直下に取り出す
D:\Pictures\100ANDRO\より下層フォルダにあるファイルを直下に移動させます。ファイル名が重複する場合は - コピー、 - コピー (2)のような連番をつけて変更されます。
空になったフォルダを削除するにはdeleteEmptyFoldersを使います。
CONST FOF_RENAMEONCOLLISION = 8
DIM folderspec = "D:\Pictures\100ANDRO\"
DIM array = getFileList(folderspec)
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(folderspec)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
FOR item IN array
IF FSO.FolderExists(item) THEN CONTINUE
PRINT Folder.Self.Path
PRINT item
Folder.MoveHere(item, FOF_RENAMEONCOLLISION)
NEXT
//////////////////////////////////////////////////
// 【引数】
// folderspec : フォルダのパス
// TextStream : TextStreamオブジェクト
// filename : 一時ファイル名
// bool : 再帰呼び出しの深さが最上部かを表すブール値
// 【戻り値】
//
//////////////////////////////////////////////////
FUNCTION getFileList(folderspec, TextStream = NOTHING, filename = "", bool = TRUE)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
IFB TextStream = NOTHING THEN
CONST TemporaryFolder = 2
DIM TempFolder = FSO.GetSpecialFolder(TemporaryFolder)
DIM TempFolderspec = TempFolder.Path
DIM name = FSO.GetTempName
filename = FSO.BuildPath(Tempfolderspec, name)
TextStream = FSO.CreateTextFile(filename)
ENDIF
DIM Folder = FSO.GetFolder(folderspec)
DIM Folders = Folder.SubFolders
FOR Folder IN Folders
getFileList(Folder.Path, TextStream, filename, FALSE)
FOR File IN Folder.Files
TextStream.WriteLine(File.Path)
NEXT
NEXT
IFB bool THEN
TextStream.Close
TextStream = FSO.OpenTextFile(filename)
DIM str = TextStream.ReadAll
TextStream.Close
FSO.DeleteFile(filename)
RESULT = SPLIT(str, "<#CR>")
ENDIF
FEND
使用関数
フォルダ内の音声ファイルをすべて再生
HASHTBL iColumn
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace("C:\Windows\Media")
FOR i = 0 TO 350
iColumn[Folder.GetDetailsOf(EMPTYPARAM, i)] = i
NEXT
DIM FolderItems = Folder.Items
DIM extensions[] = ".wav", ".mid", ".avi", ".mp3"
FOR FolderItem IN FolderItems
DIM path = FolderItem.Path
IF inArray(Folder.GetDetailsOf(FolderItem, iColumn["ファイル拡張子"]), extensions) = FALSE THEN CONTINUE
FUKIDASI(path)
SOUND(path, TRUE)
NEXT
//////////////////////////////////////////////////
// 【引数】
// needle : 探す値
// haystack : 配列
// strict : 型も同じかチェックします
// 【戻り値】
// TRUE : 配列中に指定した値が存在する、FALSE : 配列中に指定した値が存在しない
//////////////////////////////////////////////////
FUNCTION inArray( needle, haystack[], strict = FALSE)
DIM res = FALSE
FOR item IN haystack
IFB needle = item THEN
IFB strict THEN
IFB VARTYPE(needle) = VARTYPE(item) THEN
res = TRUE
BREAK
ENDIF
ELSE
res = TRUE
BREAK
ENDIF
ENDIF
NEXT
RESULT = res
FEND
使用関数
指定したファイルをゴミ箱に移動する
CONST ssfBITBUCKET = 10
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfBITBUCKET)
DIM source = "D:\Desktop\sample.txt"
Folder.MoveHere(source)
使用関数
解説
デスクトップのパスを取得
CONST ssfDesktop = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDesktop)
PRINT Folder.Self.Path
結果
D:\Desktop
使用関数
解説
デスクトップにあるアイテムの数
CONST ssfDesktop = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDesktop)
DIM FolderItems = Folder.Items
PRINT FolderItems.Count
結果
25
使用関数
右クリックメニュー取得
CONST ssfDesktop = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDesktop)
DIM FolderItem = Folder.ParseName("log.txt")
DIM FolderItemVerbs = FolderItem.Verbs
FOR FolderItemVerb IN FolderItemVerbs
PRINT FolderItemVerb.Name
NEXT
結果
開く(&O)
印刷(&P)
編集(&E)
ALZipで圧縮(&L)
管理者権限で圧縮(&Y)
"log.zip" で圧縮(&Q)
コピー(&C)
削除(&D)
共有
以前のバージョンの復元(&V)
切り取り(&T)
コピー(&C)
ショートカットの作成(&S)
削除(&D)
名前の変更(&M)
プロパティ(&R)
使用関数
指定フォルダ内の拡張子をすべて小文字にする
CONST ssfDESKTOP = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM folderspec = Shell.NameSpace(ssfDESKTOP).Self.Path
DIM Folder = Shell.NameSpace(folderspec + "\test\")
DIM FolderItems = Folder.Items
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
FOR FolderItem IN FolderItems
DIM path = FolderItem.Path
WITH FSO
DIM filename1 = .GetParentFolderName(path) + "\" + .GetBaseName(path) + "." + .GetExtensionName(path)
DIM filename2 = .GetBaseName(path) + "." + STRCONV(.GetExtensionName(path), SC_LOWERCASE)
ENDWITH
DOSCMD("RENAME <#DBL>" + filename1 + "<#DBL> <#DBL>" + filename2 + "<#DBL>")
NEXT
使用関数
解説
UWSC.INIのDefaultFontを変更する
CONST ssfFONTS = 20
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfFONTS)
DIM FolderItems = Folder.Items
DIM array[-1]
FOR FolderItem IN FolderItems
arrayPush(array, FolderItem.Name)
NEXT
QSORT(array, QSRT_UNICODEA)
SHIFTARRAY(array, 1)
array[0] = "(なし)"
DIM filename = "C:\Users\" + BETWEENSTR(DOSCMD("SET"), "USERNAME=", "<#CR>") + "\AppData\Roaming\UWSC\UWSC.INI"
DIM str = SPLIT(READINI("SET", "DefaultFont", filename), ",")[0]
DIM font = SLCTBOX(SLCT_CMB OR SLCT_STR, 0, "フォントを選択してください。(現在:" + str + ")", array)
IF font = "(なし)" THEN font = ""
IF font <> -1 THEN WRITEINI("SET", "DefaultFont", font + ",", filename)
//////////////////////////////////////////////////
// 【引数】
// array : 要素を追加する配列(参照引数)
// values : 追加する要素をvalue1から指定
// 【戻り値】
// 処理後の配列の要素の数
//////////////////////////////////////////////////
FUNCTION arrayPush(var array[], value1 = EMPTY, value2 = EMPTY, value3 = EMPTY, value4 = EMPTY, value5 = EMPTY, value6 = EMPTY, value7 = EMPTY, value8 = EMPTY, value9 = EMPTY, value10 = EMPTY, value11 = EMPTY, value12 = EMPTY, value13 = EMPTY, value14 = EMPTY, value15 = EMPTY, value16 = EMPTY)
DIM i = 1
WHILE EVAL("value" + i) <> EMPTY
DIM res = RESIZE(array, UBound(array) + 1)
array[res] = EVAL("value" + i)
i = i + 1
WEND
RESULT = LENGTH(array)
FEND
//////////////////////////////////////////////////
// 【引数】
// section : セクション
// key : キー(Delete関数は省略可)
// value : 値
// path : INIファイルのパス
// default : セクションとキーが存在しなかった場合に返す値
// 【戻り値】
//
//////////////////////////////////////////////////
MODULE INI
DEF_DLL GetPrivateProfileStringW(wstring,wstring,wstring,var pwchar,dword,wstring):dword:kernel32
DEF_DLL WritePrivateProfileStringW(wstring,wstring,wstring,wstring):bool:kernel32
FUNCTION Read(section = NULL, key = NULL, path = NULL, default = EMPTY)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
IFB path = NULL THEN
path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
ELSE
path = FSO.GetAbsolutePathName(path)
ENDIF
DIM n = 1024
DIM buffer = FORMAT(CHR(0), n)
IFB GetPrivateProfileStringW(section, key, default, buffer, n, path) = 0 THEN
RESULT = default
ELSE
RESULT = SLICE(SPLIT(buffer, CHR(0), TRUE))
IF section <> NULL AND key <> NULL THEN RESULT = RESULT[0]
ENDIF
FEND
FUNCTION Write(section, key, value, path = NULL)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
IFB path = NULL THEN
path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
ELSE
path = FSO.GetAbsolutePathName(path)
ENDIF
RESULT = WritePrivateProfileStringW(section, key, value, path)
FEND
PROCEDURE Delete(section, key = NULL, path = NULL)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
IFB path = NULL THEN
path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
ELSE
path = FSO.GetAbsolutePathName(path)
ENDIF
PRINT WritePrivateProfileStringW(section, key, NULL, path)
FEND
FUNCTION escape(value)
DIM esc = ";#=:"
FOR i = 1 TO LENGTH(esc)
DIM s = COPY(esc, i, 1)
value = REPLACE(value, s, "\" + s)
NEXT
RESULT = value
FEND
FUNCTION unescape(value)
DIM esc = ";#=:"
FOR i = 1 TO LENGTH(esc)
DIM s = COPY(esc, i, 1)
value = REPLACE(value, "\" + s, s)
NEXT
RESULT = value
FEND
ENDMODULE
//////////////////////////////////////////////////
// 【引数】
// inputs : 繰り返す文字列
// multiplier : inputsを繰り返す回数
// 【戻り値】
// inputsをmultiplier回を繰り返した文字列を返します
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
DIM res = ""
FOR n = 1 TO multiplier
res = res + inputs
NEXT
RESULT = res
FEND
//////////////////////////////////////////////////
// 【引数】
// arrayname : 上限値を求める配列の名前
// dimension : 返す次元を示す整数
// 【戻り値】
// 配列の上限値
//////////////////////////////////////////////////
FUNCTION UBound(arrayname[], dimension = 1)
RESULT = EVAL("RESIZE(arrayname" + strRepeat("[0]", dimension - 1) + ")")
FEND
使用関数
デフォルトプリンターを取得
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
使用関数
歌ネットから歌詞を取得してテキストファイルに保存
CONST ssfDesktop = 0
DIM IE = CREATEOLEOBJ("InternetExplorer.Application")
IE.Visible = TRUE
IE.Navigate("https://www.uta-net.com/song/280568/")
BusyWait(IE)
DIM element, elements, name, lyrics
element = IE.document.getElementById("view_kashi")
elements = element.getElementsByClassName("title")
name = TRIM(elements.Item(0).innerText)
element = IE.document.getElementById("kashi_area")
lyrics = element.innerText
IE.Quit
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDesktop)
DIM path = Folder.Self.Path
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
path = uniqueFilename(FSO.BuildPath(path, name + ".txt"))
DIM FID = FOPEN(path, F_READ OR F_WRITE)
FPUT(FID, lyrics)
FCLOSE(FID)
//////////////////////////////////////////////////
// 【引数】
// array : 要素を追加する配列(参照引数)
// values : 追加する要素をvalue1から指定
// 【戻り値】
// 処理後の配列の要素の数
//////////////////////////////////////////////////
FUNCTION arrayPush(var array[], value1 = EMPTY, value2 = EMPTY, value3 = EMPTY, value4 = EMPTY, value5 = EMPTY, value6 = EMPTY, value7 = EMPTY, value8 = EMPTY, value9 = EMPTY, value10 = EMPTY, value11 = EMPTY, value12 = EMPTY, value13 = EMPTY, value14 = EMPTY, value15 = EMPTY, value16 = EMPTY)
DIM i = 1
WHILE EVAL("value" + i) <> EMPTY
DIM res = RESIZE(array, UBound(array) + 1)
array[res] = EVAL("value" + i)
i = i + 1
WEND
RESULT = LENGTH(array)
FEND
//////////////////////////////////////////////////
// 【引数】
// needle : 検索する値
// haystack : 配列
// 【戻り値】
// needleが見つかった場合に配列のキー
//////////////////////////////////////////////////
FUNCTION arraySearch(needle, haystack[])
DIM i = 0
FOR item IN haystack
IFB item = needle THEN
RESULT = i
EXIT
ENDIF
i = i + 1
NEXT
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
//////////////////////////////////////////////////
// 【引数】
// 文字列 or 数値 : 取得したい<a href="https://uwsc.jp/com/ie/" >InternetExplorer オブジェクト</a>のタイトル・URLもしくは数値を指定
// 完全一致フラグ : (TRUE : 文字列が完全一致したものを取得、FALSE : 文字列の一部を含むものを取得)
// 【戻り値】
// 条件に一致する<a href="https://uwsc.jp/com/ie" >InternetExplorer</a>
//////////////////////////////////////////////////
FUNCTION getIEObj(str, flg = FALSE)
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM ShellWindows = Shell.Windows
DIM IE[-1]
FOR i = 0 TO ShellWindows.Count - 1
TRY
IFB ShellWindows.Item(i).Name = "Internet Explorer" THEN
arrayPush(IE, ShellWindows.Item(i))
ENDIF
EXCEPT
ENDTRY
NEXT
SELECT CHKNUM(str)
CASE TRUE
IFB str = 0 THEN
RESULT = LENGTH(IE)
ELSE
IF str < 0 THEN str = str + LENGTH(IE) + 1
TRY
RESULT = IE[str-1]
EXCEPT
RESULT = ERR_VALUE
ENDTRY
ENDIF
CASE FALSE
DIM pattern = IIF(flg, "^" + str + "$", str)
DIM titleList = SLICE(IE)
FOR i = 0 TO UBound(titleList)
titleList[i] = titleList[i].Document.title
NEXT
DIM urlList = SLICE(IE)
FOR i = 0 TO UBound(urlList)
urlList[i] = urlList[i].Document.URL
NEXT
DIM num = ERR_VALUE
SELECT TRUE
CASE pregGrep(pattern, titleList) <> FALSE; num = arraySearch(pregGrep(pattern, titleList)[0], titleList)
CASE pregGrep(pattern, urlList) <> FALSE; num = arraySearch(pregGrep(pattern, urlList)[0], urlList)
SELEND
TRY
RESULT = IE[num]
EXCEPT
RESULT = ERR_VALUE
ENDTRY
SELEND
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
//////////////////////////////////////////////////
// 【引数】
// pattern : 検索するパターンを表す文字列
// array : 検索される配列
// 【戻り値】
//
//////////////////////////////////////////////////
FUNCTION pregGrep(pattern, array[], flags = 0)
DIM res[-1]
FOR item IN array
IF reTest(item, pattern) THEN arrayPush(res, item)
NEXT
RESULT = SLICE(res)
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
//////////////////////////////////////////////////
// 【引数】
// arrayname : 上限値を求める配列の名前
// dimension : 返す次元を示す整数
// 【戻り値】
// 配列の上限値
//////////////////////////////////////////////////
FUNCTION UBound(arrayname[], dimension = 1)
RESULT = EVAL("RESIZE(arrayname" + strRepeat("[0]", dimension - 1) + ")")
FEND
//////////////////////////////////////////////////
// 【引数】
// path : ファイルのパス
// 【戻り値】
// 重複しないファイル名
//////////////////////////////////////////////////
FUNCTION uniqueFilename(path)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
IFB FSO.FileExists(path) THEN
DIM fol = FSO.GetParentFolderName(path)
DIM filename = FSO.GetBaseName(path)
DIM extension = FSO.GetExtensionName(path)
DIM i = 2
WHILE FSO.FileExists(FSO.BuildPath(fol, filename + " (" + i + ")." + extension))
i = i + 1
WEND
RESULT = FSO.BuildPath(fol, filename + " (" + i + ")." + extension)
ELSE
RESULT = path
ENDIF
FEND
使用関数
指定したファイルがショートカットかを取得
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\UWSC Pro\")
DIM FolderItem = Folder.ParseName("UWSC Pro.lnk")
PRINT FolderItem.IsLink()
結果
True
使用関数
解説
指定したフォルダの曲名と合計時間を出力
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:日、ww:週、h:時、n:分、s:秒)
// num : dateに加算する値。未来は正、過去は負で指定
// date : 時間間隔を加算する日付
// 【戻り値】
// 日時(date)に、指定した単位(interval)の時間(num)を加算して返します
//////////////////////////////////////////////////
FUNCTION dateAdd(interval, num, date)
DIM year, month, day, d
GETTIME(0, date)
DIM time = G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
SELECT interval
CASE "yyyy"
d = (G_TIME_YY + num) + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
IF time <> "00:00:00" THEN d = d + " " + time
CASE "m"
IFB num > 0 THEN
year = G_TIME_YY + INT((G_TIME_MM + num) / 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
IF time <> "00:00:00" THEN d = d + " " + time
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
//////////////////////////////////////////////////
// 【引数】
// array : 最大公約数を求める数値を格納した配列
// 【戻り値】
// 最大公約数
//////////////////////////////////////////////////
FUNCTION GCD(array[])
DIM c = LENGTH(array)
DIM rem = array[c-1] MOD array[c-2]
IFB rem = 0 THEN
IFB LENGTH(array) = 2 THEN
RESULT = array[c-2]
EXIT
ENDIF
RESIZE(array, c-2)
RESULT = GCD(array)
EXIT
ENDIF
array[c-1] = array[c-2]
array[c-2] = rem
RESULT = GCD(array)
FEND
//////////////////////////////////////////////////
// 【引数】
// date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”)
// m : 第一引数の指定日からプラスマイナスm月とする
// 【戻り値】
// 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
//////////////////////////////////////////////////
// 【引数】
// date : 日付文字列(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”)もしくはシリアル値
// type : 取得する曜日番号の種類を示す0〜3または11〜17の値。1と17は日曜日を1、2と11は月曜日を1とカウントします。11以降はExcel2010で追加された値で、互換性を保つために重複した値があります。
// 【戻り値】
// typeで指定した種類によって以下の値を返します。 : (0 : 0(日曜)〜6(土曜)、1 : 1(日曜)~7(土曜)、2 : 1(月曜)~7(日曜)、3 : 0(月曜)〜6(日曜)、11 : 1(月曜)~7(日曜)、12 : 1(火曜)~7(月曜)、13 : 1(水曜)~7(火曜)、14 : 1(木曜)~7(水曜)、15 : 1(金曜)~7(木曜)、16 : 1(土曜)~7(金曜)、17 : 1(日曜)~7(土曜))
//////////////////////////////////////////////////
FUNCTION getWeekday(date, type = 1)
IF VARTYPE(date) <> 258 THEN date = text(date, "yyyy/mm/dd")
GETTIME(0, date)
DIM w = G_TIME_WW
SELECT TRUE
CASE type = 0
RESULT = w
CASE type = 1
RESULT = w + 1
CASE type = 2
RESULT = IIF(w=0, 7, w)
CASE type = 3
RESULT = (w+6) MOD 7
CASE type >= 11
RESULT = ((getWeekday(date, 2) + 17 - type) MOD 7) + 1
SELEND
FEND
//////////////////////////////////////////////////
// 【引数】
// serial : シリアル値もしくは時刻文字列
// 【戻り値】
// 時刻から時間を表す0〜23の範囲の値
//////////////////////////////////////////////////
FUNCTION Hour(serial)
IF VARTYPE(serial) = 258 THEN serial = timeValue(serial)
RESULT = INT(serial * 24) MOD 24
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
//////////////////////////////////////////////////
// 【引数】
// date : 存在するかを調べる日付文字列。YYYYMMDD or YYYY/MM/DD or YYYY-MM-DDのいずれかの形式。
// 【戻り値】
// TRUE : 日付として認識できる、FALSE : 日付として認識できない
//////////////////////////////////////////////////
FUNCTION isDate(date)
TRY
GETTIME(0, date)
RESULT = TRUE
EXCEPT
RESULT = FALSE
ENDTRY
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
//////////////////////////////////////////////////
// 【引数】
// 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 : フォーマット
// 【戻り値】
// 数値を表示書式に基づいて変換した文字列
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// 【引数】
// 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"
serial = VAL(serial)
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)
DIM aaa[] = "日", "月", "火", "水", "木", "金", "土"
DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"
DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
RESULT = EVAL(Matches.Item(0).SubMatches(0) + "[" + getWeekday(G_TIME_WW, 1) + "]")
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, ".")) <= 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
//////////////////////////////////////////////////
// 【引数】
// str : 時刻文字列。hh:nn:ss AM/PM、hh:nn AM/PM、hh AM/PM、hh:nn:ss、hh:nn、hh時nn分ss秒、hh時nn分のいずれかの形式を指定。
// 【戻り値】
// シリアル値 (例)0…00:00:00、0.5…12:00:00、0.999988425925926…23:59:59
//////////////////////////////////////////////////
FUNCTION timeValue(str)
DIM serial = 0
DIM Matches
DIM pattern = "(\d+)"
DIM hh = "(0?[0-9]|1[0-2])"
DIM ampm = "([AP]M|[ap]m)"
SELECT TRUE
CASE reTest(str, "\b" + hh + ":" + pattern + ":" + pattern + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + ":" + pattern + ":" + pattern + " " + ampm + "\b")
WITH Matches.Item(0)
serial = timeValue(.SubMatches(0) + " " + .SubMatches(3)) + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + hh + ":" + pattern + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + ":" + pattern + " " + ampm + "\b")
WITH Matches.Item(0)
serial = timeValue(.SubMatches(0) + " " + .SubMatches(2)) + VAL(.SubMatches(1)) / 1440
ENDWITH
CASE reTest(str, "\b" + hh + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + " " + ampm + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0) MOD 12) + IIF(reTest(.SubMatches(1), "AM|am"), 0, 12)
serial = serial / 24
ENDWITH
CASE reTest(str, "\b" + pattern + ":" + pattern + ":" + pattern + "\b")
Matches = reExecute(str, "\b" + pattern + ":" + pattern + ":" + pattern + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + pattern + ":" + pattern + "\b")
Matches = reExecute(str, "\b" + pattern + ":" + pattern + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440
ENDWITH
CASE reTest(str, "\b" + pattern + "時" + pattern + "分" + pattern + "秒")
Matches = reExecute(str, "\b" + pattern + "時" + pattern + "分" + pattern + "秒")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + pattern + "時" + pattern + "分")
Matches = reExecute(str, "\b" + pattern + "時" + pattern + "分")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440
ENDWITH
DEFAULT
serial = ERR_VALUE
SELEND
RESULT = serial - INT(serial)
FEND
//////////////////////////////////////////////////
// 【引数】
// arrayname : 上限値を求める配列の名前
// dimension : 返す次元を示す整数
// 【戻り値】
// 配列の上限値
//////////////////////////////////////////////////
FUNCTION UBound(arrayname[], dimension = 1)
RESULT = EVAL("RESIZE(arrayname" + strRepeat("[0]", dimension - 1) + ")")
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\")
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:日、ww:週、h:時、n:分、s:秒)
// num : dateに加算する値。未来は正、過去は負で指定
// date : 時間間隔を加算する日付
// 【戻り値】
// 日時(date)に、指定した単位(interval)の時間(num)を加算して返します
//////////////////////////////////////////////////
FUNCTION dateAdd(interval, num, date)
DIM year, month, day, d
GETTIME(0, date)
DIM time = G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
SELECT interval
CASE "yyyy"
d = (G_TIME_YY + num) + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
IF time <> "00:00:00" THEN d = d + " " + time
CASE "m"
IFB num > 0 THEN
year = G_TIME_YY + INT((G_TIME_MM + num) / 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
IF time <> "00:00:00" THEN d = d + " " + time
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
//////////////////////////////////////////////////
// 【引数】
// array : 最大公約数を求める数値を格納した配列
// 【戻り値】
// 最大公約数
//////////////////////////////////////////////////
FUNCTION GCD(array[])
DIM c = LENGTH(array)
DIM rem = array[c-1] MOD array[c-2]
IFB rem = 0 THEN
IFB LENGTH(array) = 2 THEN
RESULT = array[c-2]
EXIT
ENDIF
RESIZE(array, c-2)
RESULT = GCD(array)
EXIT
ENDIF
array[c-1] = array[c-2]
array[c-2] = rem
RESULT = GCD(array)
FEND
//////////////////////////////////////////////////
// 【引数】
// date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”)
// m : 第一引数の指定日からプラスマイナスm月とする
// 【戻り値】
// 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
//////////////////////////////////////////////////
// 【引数】
// date : 日付文字列(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”)もしくはシリアル値
// type : 取得する曜日番号の種類を示す0〜3または11〜17の値。1と17は日曜日を1、2と11は月曜日を1とカウントします。11以降はExcel2010で追加された値で、互換性を保つために重複した値があります。
// 【戻り値】
// typeで指定した種類によって以下の値を返します。 : (0 : 0(日曜)〜6(土曜)、1 : 1(日曜)~7(土曜)、2 : 1(月曜)~7(日曜)、3 : 0(月曜)〜6(日曜)、11 : 1(月曜)~7(日曜)、12 : 1(火曜)~7(月曜)、13 : 1(水曜)~7(火曜)、14 : 1(木曜)~7(水曜)、15 : 1(金曜)~7(木曜)、16 : 1(土曜)~7(金曜)、17 : 1(日曜)~7(土曜))
//////////////////////////////////////////////////
FUNCTION getWeekday(date, type = 1)
IF VARTYPE(date) <> 258 THEN date = text(date, "yyyy/mm/dd")
GETTIME(0, date)
DIM w = G_TIME_WW
SELECT TRUE
CASE type = 0
RESULT = w
CASE type = 1
RESULT = w + 1
CASE type = 2
RESULT = IIF(w=0, 7, w)
CASE type = 3
RESULT = (w+6) MOD 7
CASE type >= 11
RESULT = ((getWeekday(date, 2) + 17 - type) MOD 7) + 1
SELEND
FEND
//////////////////////////////////////////////////
// 【引数】
// serial : シリアル値もしくは時刻文字列
// 【戻り値】
// 時刻から時間を表す0〜23の範囲の値
//////////////////////////////////////////////////
FUNCTION Hour(serial)
IF VARTYPE(serial) = 258 THEN serial = timeValue(serial)
RESULT = INT(serial * 24) MOD 24
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
//////////////////////////////////////////////////
// 【引数】
// date : 存在するかを調べる日付文字列。YYYYMMDD or YYYY/MM/DD or YYYY-MM-DDのいずれかの形式。
// 【戻り値】
// TRUE : 日付として認識できる、FALSE : 日付として認識できない
//////////////////////////////////////////////////
FUNCTION isDate(date)
TRY
GETTIME(0, date)
RESULT = TRUE
EXCEPT
RESULT = FALSE
ENDTRY
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
//////////////////////////////////////////////////
// 【引数】
// 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 : フォーマット
// 【戻り値】
// 数値を表示書式に基づいて変換した文字列
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// 【引数】
// 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"
serial = VAL(serial)
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)
DIM aaa[] = "日", "月", "火", "水", "木", "金", "土"
DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"
DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
RESULT = EVAL(Matches.Item(0).SubMatches(0) + "[" + getWeekday(G_TIME_WW, 1) + "]")
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, ".")) <= 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
//////////////////////////////////////////////////
// 【引数】
// str : 時刻文字列。hh:nn:ss AM/PM、hh:nn AM/PM、hh AM/PM、hh:nn:ss、hh:nn、hh時nn分ss秒、hh時nn分のいずれかの形式を指定。
// 【戻り値】
// シリアル値 (例)0…00:00:00、0.5…12:00:00、0.999988425925926…23:59:59
//////////////////////////////////////////////////
FUNCTION timeValue(str)
DIM serial = 0
DIM Matches
DIM pattern = "(\d+)"
DIM hh = "(0?[0-9]|1[0-2])"
DIM ampm = "([AP]M|[ap]m)"
SELECT TRUE
CASE reTest(str, "\b" + hh + ":" + pattern + ":" + pattern + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + ":" + pattern + ":" + pattern + " " + ampm + "\b")
WITH Matches.Item(0)
serial = timeValue(.SubMatches(0) + " " + .SubMatches(3)) + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + hh + ":" + pattern + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + ":" + pattern + " " + ampm + "\b")
WITH Matches.Item(0)
serial = timeValue(.SubMatches(0) + " " + .SubMatches(2)) + VAL(.SubMatches(1)) / 1440
ENDWITH
CASE reTest(str, "\b" + hh + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + " " + ampm + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0) MOD 12) + IIF(reTest(.SubMatches(1), "AM|am"), 0, 12)
serial = serial / 24
ENDWITH
CASE reTest(str, "\b" + pattern + ":" + pattern + ":" + pattern + "\b")
Matches = reExecute(str, "\b" + pattern + ":" + pattern + ":" + pattern + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + pattern + ":" + pattern + "\b")
Matches = reExecute(str, "\b" + pattern + ":" + pattern + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440
ENDWITH
CASE reTest(str, "\b" + pattern + "時" + pattern + "分" + pattern + "秒")
Matches = reExecute(str, "\b" + pattern + "時" + pattern + "分" + pattern + "秒")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + pattern + "時" + pattern + "分")
Matches = reExecute(str, "\b" + pattern + "時" + pattern + "分")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440
ENDWITH
DEFAULT
serial = ERR_VALUE
SELEND
RESULT = serial - INT(serial)
FEND
//////////////////////////////////////////////////
// 【引数】
// arrayname : 上限値を求める配列の名前
// dimension : 返す次元を示す整数
// 【戻り値】
// 配列の上限値
//////////////////////////////////////////////////
FUNCTION UBound(arrayname[], dimension = 1)
RESULT = EVAL("RESIZE(arrayname" + strRepeat("[0]", dimension - 1) + ")")
FEND
結果
09:24:43
使用関数
コマンドプロンプトのショートカットを生成
デスクトップにコマンドプロンプトへのショートカットリンクを作成します。
CONST ssfDesktop = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM path = Shell.NameSpace(ssfDesktop).Self.Path
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
DIM WshShortcut = WshShell.CreateShortcut(path + "\cmd.lnk")
WITH WshShortcut
.IconLocation = "C:\Windows\system32\imageres.dll, 11"
.TargetPath = "C:\WINDOWS\system32\cmd.exe"
.WindowStyle = 3
.WorkingDirectory = "%LOCALAPPDATA%"
.Save
ENDWITH
結果
使用関数
解説
デスクトップにChromeのショートカットを作成
デスクトップにGoogle Chromeで[createLink url="https://google.co.jp" title="https://google.co.jp"]をシークレットモードで起動するショートカットを作成します。
CONST ssfDesktop = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
DIM Folder2 = Shell.NameSpace(ssfDesktop)
DIM path = Folder2.Self.Path + "\Chrome.lnk"
DIM WshShortcut = WshShell.CreateShortcut(path)
WITH WshShortcut
DIM chromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
.Description = "Chromeをシークレットモードで起動します。"
.Hotkey = "Ctrl+Shift+C"
.IconLocation = chromePath + ",7"
.TargetPath = chromePath
.WindowStyle = 3
.Save
ENDWITH
Folder = Shell.NameSpace(FSO.GetParentFolderName(path))
DIM FolderItem = Folder.ParseName(FSO.GetFileName(path))
DIM ShellLinkObject = FolderItem.Getlink()
DIM Args[] = "--incognito", "https://google.co.jp"
WITH ShellLinkObject
.Arguments = JOIN(Args)
.Save
ENDWITH
結果
使用関数
解説
デスクトップにあるフォルダ一覧を取得
CONST ssfDesktop = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDesktop)
DIM path = Folder.Self.Path
GETDIR(path, "\")
FOR item IN GETDIR_FILES
PRINT item
NEXT
使用関数
ファイルシステムかどうか
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace("C:\Windows")
DIM FolderItems = Folder.Items
FOR n = 0 TO FolderItems.Count - 1
DIM FolderItem = FolderItems.Item(n)
WITH FolderItem
PRINT .IsFileSystem + "<#TAB>" + .Name
ENDWITH
NEXT
使用関数