解決済

clip!clip!
Ads By Google

VBScriptの処理でログを出す処理作っているのですが処理中に何らかの原因で正常な処理が出来なかった

場合にエラーログを出したいのですが冗長にならないようにしたいのですが・・・どうすればよいでしょうか?
Option Explicit

Const ForAppending = 8

Dim objFileSysFolder
Dim objOutFile
Dim objFileSysText
Dim strScriptPath
Dim strCheckPath
Dim strCreatePath
Dim strDate
Dim strCreateFile



If XXXX then
aaaa
Else
bbbb
End If



If YYYY then
CCCC
Else
DDDD
End If



If ZZZZ then
EEEE
Else
fffff
End If

Set objFileSysFolder = CreateObject("Scripting.FileSystemObject")
strCheckPath = objFileSysFolder.BuildPath("D:\","TEST")
strDate = CStr(Right("0000" & Year(Now),4) & Right("00" & Month(Now),2))

If objFileSysFolder.FolderExists(strCheckPath) = True Then
Set objFileSysText = CreateObject("Scripting.FileSystemObject")

strScriptPath = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
strCreateFile = objFileSysText.BuildPath(strScriptPath,strDate & ".log")

If objFileSysText.FileExists(strCheckPath) = True Then
Set objOutFile = objFileSysText.OpenTextFile(strCreateFile,ForAppending)
objOutFile.WriteLine "Date[" & date & "] " & _
"Time[" & time & "] " & _
"User[" & "OK" & "]"
objOutFile.Close
Else
Set objOutFile = objFileSysText.OpenTextFile(strCreateFile,ForAppending)
objOutFile.WriteLine "Date[" & date & "] " & _
"Time[" & time & "] " & _
"User[" & "NG" & "]"'ここでメッセージを変えたい
objOutFile.Close
End If
End If

Set objFileSysFolder = Nothing
Set objFileSysText = Nothing
Set objOutFile = Nothing
こういったログのルーチンをあるとしますが、If~Else~End Ifの部分でElse以降の場合メッセージを変えるにはどうすればいいでしょうか?

2008-12-15 00:42の質問
この質問と回答を読んで役に立った場合は「役に立つ質問」に投票してください。投票が多い質問は、役に立つ質問一覧に掲載され、より多くの人に見てもらうことができます。

回答(1)

1.

2008-12-15 03:27:53ベスト
メッセージを変えて、
objOutFile.WriteLine "違うメッセージ"
とすればいいように思います。
勘違いコメントだったら補足下さい。

冗長でなくするには、1つには共通部分をくくり出すことです。
例えば、
CreateObject("Scripting.FileSystemObject")
FileSystemObject は、ひとつ作れば使い回しができます。

IF … THEN
処理A
処理B
処理Z
ELSE
処理A
処理C
処理Z
END IF
のようになっていて、それぞれの処理に特別な副作用がないなら

処理A
IF … THEN
処理B
ELSE
処理C
END IF
処理Z
のようにできます。
自信度 : 自信なし 回答レベル : アドバイス
Ads By Google

コメント

まだコメントがありません

トラックバック(2)

トラックバックURL: