2016-11-27 10 views
1

私はVBで絶対初心者ですので、愚かな質問をするかもしれません。
バッチファイルを介してVBスクリプトがトリガーされ、最終日にデータがインポートされます。 以下は、VBおよびバッチファイルのコードです。
コードにエラーがある場合はお知らせください。自動インポートスクリプトが機能しない

VBスクリプト

rem 
rem XLink_Import.vbs 
rem 

Set oShell = WScript.CreateObject("WScript.Shell") 

' filename = oShell.ExpandEnvironmentStrings("today_xlink.bat") 
' Set objFileSystem = CreateObject("Scripting.fileSystemObject") 
' Set oFile = objFileSystem.CreateTextFile(filename, TRUE) 

Dim i 
Dim ImportStartOffset, ImportedNumberOfDays 

If WScript.Arguments.length > 0 Then 
    For i=0 to WScript.Arguments.length-1 
     Arg = WScript.Arguments(i) 
     If Left(Arg,1) = "-" Then 
      If (Arg = "-o") Then 
       ImportStartOffset = WScript.Arguments(i+1) 
      End if 
      If (Arg = "-n" or Arg = "-l") Then 
       ImportedNumberOfDays = WScript.Arguments(i+1) 
      End if 
     End if 
    Next 
End If 

rem Prepare the import start date 

Dim Dy, Mth 
Dim ImportDate 
ImportDate = Now + ImportStartOffset 
Dy = Day(ImportDate) 
Mth = Month(ImportDate) 
If Len(Dy) = 1 Then Dy = "0" & Dy 
If Len(Mth) = 1 Then Mth = "0" & Mth 
ImportStartDate = Dy & "/" & Mth & "/" & Year(ImportDate) 

rem Prepare import script to run (not useed yet) 
rem oFile.WriteLine("isps_ul.exe -t -d " & todaydate & " -L 1") 
rem oFile.Close 

rem Run XLink import 

wscript.echo "isps_ul.exe -t -d " & ImportStartDate & " -L " & ImportedNumberOfDays 
oShell.Run "isps_ul.exe -t -d " & ImportStartDate & " -L " & ImportedNumberOfDays, 1, true 

バッチファイル

@echo off 
rem 
rem XLink_Import.bat 
rem 
rem Manually starts an Xlink import starting today + a StartOffset of some days. 
rem Imported number of days can also be set. 
rem 

set ImportStartOffset=0 
set ImportedNumberOfDays=1 

cscript XLink_Import.vbs -o %ImportStartOffset% -n %ImportedNumberOfDays% 

pause 
+0

スクリプトの実行中にエラーが発生しますか?もしそうなら、どちらの行に?なぜバッチ、あなたはスクリプト自体で設定を行うことができますか、またはコマンドラインからパラメータを使用して?変数に実行文字列を割り当ててDRYにする必要があります。 – peter

+0

こんにちは@ピーター - 返信いただきありがとうございません、私はエラーが表示されません、私は "isps_ul.exe -t -d28/11/2016 -L"というメッセージを受け取りますバッチを使用する理由は、私はこのジョブを自動化したいです私が知っている唯一の方法は、Windowsのタスクスケジューラを使用していることです。申し訳ありませんが、DRYの部分を理解しています(私の知らなかったことを教えてください) –

答えて

0

あなたには全体のことをやって、いずれかの1は十分だろう、バッチやスクリプトの両方を必要としませんバッチには特別なパラメータが必要ですが、私はそうではありませんので、私はあなたのスクリプトを以下のように少し変更します。 Windows環境に2つのconfiuration変数を保存するので、vbscriptから読み込むこともできます。他のオプションは、コマンドラインから設定ファイルを読み込んだり、スクリプト自体を保存したりすることです。

あなたの中央部には、あなたが設定(environmentvariables)で正しくこれらの日付を設定した場合、日付は省略することができ、正しいspeleldされていることを確認makig。

インポートは、まずその問題を検索しそうでない場合は、実行する必要があります"eisps_ul.exe -t -d28/11/2016 -L"例えばので、あなたは、コマンドとして表示されているものを実行することによって、前にチェックする必要があります仕事に行くされている場合。

は、私はDRYであることについての私のコメントに意味することは、あなたが変数に連結されたコマンドを格納して表示し、実行するためにそれを使用することができ、あなたのコマンドの場合には、物事を繰り返してはならないことを意味します。

Dim ImportStartOffset, ImportedNumberOfDays, oShell, command, Dy, Mth, ImportDate, ImportStartDate 
Constant WaitOnReturn = true, WindowStyle = 1 '1 = Activate and display 

'read configuration environment variables 
Set oShell   = CreateObject("WScript.Shell") 
ImportStartOffset = wshShell.ExpandEnvironmentStrings("%ImportStartOffset%") 
ImportedNumberOfDays = wshShell.ExpandEnvironmentStrings("%ImportedNumberOfDays%") 

'Prepare the import start date (not necessary if environmentvariables would be configured well) 
ImportDate = Now + ImportStartOffset 
Dy = Day(ImportDate) 
Mth = Month(ImportDate) 
If Len(Dy) = 1 Then Dy = "0" & Dy 
If Len(Mth) = 1 Then Mth = "0" & Mth 
ImportStartDate = Dy & "/" & Mth & "/" & Year(ImportDate) 

'Run XLink import 
command = "isps_ul.exe -t -d " & ImportStartDate & " -L " & ImportedNumberOfDays 
wscript.echo command 
oShell.Run command, WindowStyle, WaitOnReturn 
Set oShell = Nothing 
+0

こんにちは@ピーター、あなたの助けをたくさんありがとう私はこれをコード。 –

関連する問題