簡體   English   中英

VBS對象必需錯誤800A01A8

[英]VBS Object required error, 800A01A8

您好,我正在嘗試調試以下繼承的腳本。 錯誤在第71行的char 6上。對象需要'oFile'

我沒有任何VBS經驗,所以請保持溫柔。 該腳本進行了掃描,並將其上傳到doc存檔服務器,為其提供了唯一的文件名等。我還沒有弄清楚'ofile'是什么:/

'Feb 18, 2005

Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
hiddenCount = 0
'Wscript.Echo Wscript.Arguments(0)
If Wscript.Arguments.Count = 1 And oFSO.FolderExists(Wscript.Arguments(0))  Then
    Set scanFiles = oFSO.GetFolder(Wscript.Arguments(0)).Files
    For Each oFile In scanFiles
    If oFile.Attributes and 2 Then
    hiddenCount = hiddenCount + 1
End If
        Next
Else
    Set scanFiles = WScript.Arguments
End If
fileCount = scanFiles.Count - hiddenCount
'Wscript.Echo hiddenCount
'WScript.Echo fileCount
'WScript.Quit()
Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.left=50 ' window position
oIE.top = 100 ' and other properties
oIE.height = 300
oIE.width = 350
oIE.menubar = 0 ' no menu
oIE.toolbar = 0
oIE.statusbar = 1
oIE.navigate "http://gisweb/apps/doc_archive/scan_login.php?file_count="&fileCount
'WScript.Echo fileCount
oIE.visible = 1

' Important: wait till MSIE is ready
  Do While (oIE.Busy)      
  Loop

' Wait till the user clicks the OK button
' Use the CheckVal function
' Attention: Thanks to a note from M. Harris, we can make 
' the script a bit more fool proof. We need to catch the case 
' that the user closes the form without clicking the OK button.
 On Error Resume Next  
 Do                     ' Wait till OK button is clicked
    WScript.Sleep 400
 Loop While (oIE.document.script.CheckVal()=0)

' If an error occur, because the form is closed, quit the
' script
 If err <> 0 Then
  WScript.Echo "Sorry, a run-time error occured during checking" & _
               " the OK button " & vbCRLF & _
               "Error: " & err.number & " " & _
               "I guess the form was getting closed..."
  WScript.Quit        ' end script
 End if
 On Error Goto 0    ' switch error handling off 

' User has clicked the OK button, retrieve the values
docList = oIE.Document.ValidForm.doc_id_list.Value
'MsgBox doc_id
 For i = 0 To 100000
    x = 1
 Next 
 oIE.Quit()             ' close Internet Explorer
 Set oIE = Nothing      ' reset object variable 


 docArray = Split(docList,",")
 i = 0
 For Each oFile In scanFiles
     If Not oFile.Attributes And 2 Then  **ERROR HERE**
    ext = oFSO.GetExtensionName(oFile)
    filename = "p"&right("000000"&docArray(i),6)&"."&ext
    base = Int(docArray(i) / 500) * 500
    subdir = "d"&right("000000"&base,6)
    oFSO.CopyFile oFile, "\\ditgis02\Enterprise_GIS\doc_archive\raw\"&subdir&"\"&filename, True
    i = i + 1
     End If
Next
If Wscript.Arguments.Count = 1 And oFSO.FolderExists(Wscript.Arguments(0))  Then
    Set WshShell = WScript.CreateObject("WScript.Shell")
    intButton = WshShell.Popup (fileCount&" file(s) logged and copied! Do you want to delete temporary scan files?",0,"Done!",4)
    If intButton = 6 Then
        For Each oFile In scanFiles
            oFile.Delete
        Next
    End If
Else
    WScript.Echo(fileCount&" file(s) logged and copied!")
End If
WScript.Quit()            ' Ready
' End

如果您的初始測試失敗,則看起來可能會出現問題:

If Wscript.Arguments.Count = 1 And oFSO.FolderExists(Wscript.Arguments(0))  Then
    ...
Else
    Set scanFiles = WScript.Arguments
End If

您正在將scanFiles變量設置為參數而不是文件的集合。 稍后,在第71行(發生錯誤的地方)附近,您將scanFiles視為是一個Files集合,並嘗試訪問其File對象之一的Attributes屬性:

For Each oFile In scanFiles
    If Not oFile.Attributes And 2 Then  **ERROR HERE**
    ...
Next

這將是不可能的,因為scanFiles是一個Arguments集合。 因此,我認為您需要修復初始的Else子句以終止腳本或提供某種“默認” Files集合。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM