Posershellは週単位の計算がない
前々回でPowershell 新元号換算スクリプトではPowershellでやったのですが、週単位って定数がありません。もちろん7の倍数でもできるのですが。
そこでVBSCRIPTでもやってみます。
仕様
- Vbscriptで計算させる
- InputBoxに日付を入力するが、標準では今日の日付が自動的に入る。
- 2週間後、3週間後、4週間後、28日後、30日後を計算する
- 何日後については、曜日まで出力し、元号でもだし、経過日数を求める
- タブやStringで整形する。
- YearNumber定数でだいたい何年分計算するか決める。下記は2年分程度
- IntervalNumber定数で何週単位か決める。下記は4週単位
- 日付を計算したら、スクリプトのあるフォルダにテキストファイルで出力する。
Option explicit
'https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1144732471
Dim strDate 'As String
DIm DT,DT1
Dim FSO : set fso = createObject("Scripting.FileSystemObject")
Dim strFolder:strFolder=fso.getParentFolderName(WScript.ScriptFullName)
'strFolder = CreateObject("WScript.Shell").SpecialFolders("Desktop") 'デスクトップ
'strFolder = CreateObject("WScript.Shell").SpecialFolders("MyDocuments") 'Documents
'If CreateObject("Scripting.FilesystemObject").Folderexists("E:\") Then StrFolder = "E:\" Else Wscript.Quit '任意のフォルダ
Dim varInterval
Const Week7Day = "ww"
Const YearNumber = 2
Const IntervalNumber = 4
Dim i
strDate= inputbox("日付入力","Input date",date)
DT = cDate(strDate)
if fso.FileExists(strFolder & "\ResultUnicode.txt") then fso.deletefile strFolder & "\ResultUnicode.txt",True
With FSO.CreateTextFile(strFolder & "\ResultUnicode.txt",True)
.WriteLine "Start Date : " & FormatDateTime(DT,vbLongDate)
.WriteBlankLines(1)
.WriteLine IntervalNumber & " weeks"
for i= 1 to 13 * YearNumber
.WriteLine i & vbtab & ":" & dateadd(Week7Day,IntervalNumber *i,DT)
Next
.WriteBlankLines(2)
.WriteLine "biweekly Interval"
for i= 1 to 26 * YearNumber
.WriteLine i & vbtab & ":" & dateadd(Week7Day,2*i,DT)
Next
.WriteBlankLines(2)
.WriteLine "10 days Interval"
for i = 1 to 37 * YearNumber
DT1 = DateAdd("d",10*i,DT) 'vbLongDate = 1
varInterval = DateDiff("d",Dt,Dt1,vbUseSystemDayOfWeek,vbFirstJan1)
.WriteLine i & vbtab & ":" & FormatDateTime(DT1,vbLongDate) & vbtab & " : 平成" & Year(DT1)-1988 & "/" & Right("0" & Month(DT1), 2) & "/" & Right("0" & Day(DT1), 2) & vbtab & " : " & String(4-len(cstr(varInterval)),chr(32)) & varInterval & " Days Past"
next
.WriteBlankLines(2)
.Write "Every 3 Weeks Interval" & vbCrlf 'Write method not include vbcrlf
for i= 1 to 26 * YearNumber
DT1= dateadd(Week7Day,3*i,DT)
varInterval = DateDiff("d",Dt,Dt1,vbUseSystemDayOfWeek,vbFirstJan1)
.WriteLine i & vbtab & ":" & DT1 & " : 平成" & Year(DT1)-1988 & "/" & Right("0" & Month(DT1), 2) & "/" & Right("0" & Day(DT1), 2) & VbTab & " : " & String(4-len(cstr(varInterval)),chr(32)) & varInterval & " Days Past"
Next
.WriteBlankLines(2)
.WriteLine "28 days Interval"
for i= 1 to 14 * YearNumber
DT1 = DateAdd("d",28*i,DT) 'vbLongDate = 1
varInterval = DateDiff("d",Dt,Dt1,vbUseSystemDayOfWeek,vbFirstJan1)
.WriteLine i & vbtab & ":" & FormatDateTime(DT1,vbLongDate) & VbTab & ": 平成" & Year(DT1)-1988 & "/" & Right("0" & Month(DT1), 2) & "/" & Right("0" & Day(DT1), 2) & VbTab & " : " & String(4-len(cstr(varInterval)),chr(32)) & varInterval & " Days Past"
next
.WriteLine VbCrlf & Vbcrlf & "30 days Interval"
for i= 1 to 13 * YearNumber
DT1 = DateAdd("d",30*i,DT) 'vbLongDate = 1
varInterval = DateDiff("d",Dt,Dt1,vbUseSystemDayOfWeek,vbFirstJan1)
.WriteLine i & vbtab & ":" & FormatDateTime(DateAdd("d",30*i,DT),vbLongDate) & VbTab & ":平成" & Year(DT1)-1988 & "/" & Right("0" & Month(DT1), 2) & "/" & Right("0" & Day(DT1), 2) & VbTab & " : " & String(4-len(cstr(varInterval)),chr(32)) & varInterval & " Days Past"
next
.close
end with
set fso = nothing