2010-07-16 13 views
7

Ricevo un errore "oggetto obbligatorio" sulla riga 54, l'ultima riga, quando eseguo il seguente script. Che c'è?Errore VB "oggetto richiesto"

Option Explicit 
Dim cmdString, g_strHostFile, filepath, flexnetpath, importcmd, dtmToday, dtmYesterday, dtmFileDate, param1, param2, param3, i4path, objFSO, objTextStream, g_strComputer, WshShell 
'Initialize global constants and variables. 
Const FOR_READING = 1 
g_strHostFile = "D:\dataimports\LUM_servers.txt" 
i4path = "C:\IFOR\WIN\BIN\i4blt.exe" 
filepath = "D:\DataImports\" 
flexnetpath = "C:\Program Files (x86)\Flexnet\Manager\Admin" 
importcmd = flexnetpath & "flexnet bulkimport -uadmin -padmin -f" & filepath 
dtmToday = Date() 
dtmYesterday = Date() - 1 
dtmFileDate = Year(Date) & padDate(Month(Date)) & padDate(Day(Date)) 
param1 = "-r1 -e2,4 -n " 
param2 = " -v 'Dassault Systemes' -b " 
param3 = " -g " 
WScript.Echo "i4Path: " & i4path 
WScript.Echo "FilePath: " & filepath 
WScript.Echo "flexnetpath: " & flexnetpath 
WScript.Echo "importcmd: " & importcmd 
WScript.Echo "dtmToday: " & dtmToday 
WScript.Echo "dtmYesterday: " & dtmYesterday 
WScript.Echo "dtmFileDate: " & dtmFileDate 

'Read LUM Server Names from text file. 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
If objFSO.FileExists(g_strHostFile) Then 
    Set objTextStream = objFSO.OpenTextFile(g_strHostFile, FOR_READING) 
Else 
    WScript.Echo "Input file " & g_strHostFile & " not found." 
    WScript.Quit 
End If 
'Loop through list of computers and perform tasks on each. 
Do Until objTextStream.AtEndOfStream 
    g_strComputer = objTextStream.ReadLine 
WScript.Echo "Processing Server: " & g_strComputer 
Set cmdString = i4path & param1 & g_strComputer & param2 & dtmYesterday & param3 & dtmToday & filepath & g_strComputer & "_" & dtmFileDate & "_lum.lrl" 
WScript.Echo "Processing Command: " & cmdString 
Set WshShell = WScript.CreateObject("WScript.Shell") 
WshShell.Run "cmdString" 
Loop 
objTextStream.Close 
Set WshShell = WScript.CreateObject("WScript.Shell") 
WScript.Echo "Processing Bulk Import: " & importcmd 
WshShell.Run "importcmd" 

Function padDate(intNumber) 
if intNumber <= 9 Then 
    padDate = "0" & CStr(intNumber) 
Else 
    padDate = CStr(intNumber) 
End If 
End Function 
+0

su quale linea si ottiene questo errore? – Sarfraz

+0

Sai dove si trova l'errore? Potresti usare 'WScript.Echo' o' MsgBox' con del testo solo in modo da poter restringere l'area nel codice in cui si verifica l'errore. –

+0

Riga 54, l'ultima riga. – ChuckO

risposta

6

Ci sono alcuni problemi, penso.

importcmd = flexnetpath & "flexnet bulkimport -uadmin -padmin -f" & filepath 

Probabilmente avete bisogno di alcuni spazi:

importcmd = flexnetpath & " flexnet bulkimport -uadmin -padmin -f " & filepath 

Set viene utilizzato solo con oggetti, non stringhe, quindi dovrebbe essere rimosso da questa linea:

Set cmdString = i4path & param1 & g_strComputer & param2 & dtmYesterday & param3 & dtmToday & filepath & g_strComputer & "_" & dtmFileDate & "_lum.lrl" 

Sono abbastanza sicuro o intendi

WshShell.Run importcmd 

O

WshShell.Run """" & importcmd & """" 
5

Oggetto richiesto viene generato quando si dispone di una dichiarazione come Set x = y dove x non è un tipo di oggetto, ma è invece un tipo semplice (Integer, Double, Date, etc.). Penso che la linea

Set cmdString = i4path & param1 & g_strComputer & param2 & ... 

causa l'errore, e credo che tutto quello che dovete fare è rimuovere l'istruzione Set. Penso che le stringhe non derivino da Object e quindi non hanno bisogno dell'istruzione Set.