【问题标题】:VBS Object required error, 800A01A8VBS 对象需要错误,800A01A8
【发布时间】:2015-08-19 16:04:07
【问题描述】:

您好,我正在尝试调试我在下面继承的这个脚本。错误在第 71 行 char 6。需要对象'oFile'

我没有任何vbs经验,所以请温柔。该脚本进行扫描并将其上传到文档存档服务器,为其提供唯一的文件名等。我还没有弄清楚'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

【问题讨论】:

  • PHP是如何参与的?
  • 如何运行脚本?你传递给它什么参数?
  • 我们将一个pdf文档拖入脚本中

标签: vbscript


【解决方案1】:

如果您的初始测试失败,看起来可能会出现问题:

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 集合。

【讨论】:

  • 谢谢,“默认”文件目前是“oFile”吗?如何创建新的“默认”文件部分?
  • 如果脚本没有收到有效的文件夹作为参数,您希望脚本做什么?
  • 我想我希望它终止,我将如何在“设置扫描文件”中设置一个文件夹?只是给它一个路径?再次感谢。抱歉,这有点超出我的想象。
  • 如果不存在正确的参数,只需将您的 Set scanFiles = WScript.Arguments 行更改为 WScript.Quit 即可终止脚本。如果需要,您可以选择显示一条消息 (WScript.Echo "some message"),告诉用户应该如何使用该脚本。
猜你喜欢
  • 2017-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多