2016-01-30 70 views
2

我有一个VBScript代码,让我一个错误,指出“对象需要” 和错误800A01A8第11行和字符3.错误800A01A8所需的对象

下面是代码:

Dim strWebsite 

strWebsite = "78.72.111.138:80" 

If PingSite(strWebsite) Then 
    Dim xHttp: Set xHttp = CreateObject("Microsoft.XMLHTTP") 
    Dim bStrm: Set endbStrm = CreateObject("Adodb.Stream") 
    xHttp.Open "GET", "http://?/batch/down.php", False 
    xHttp.Send 
    With bStrm 
     .Type = 1 '//binary 
     .Open 
     .Write xHttp.responseBody 
     .SaveToFile "link.txt", 2 '//overwrite 
    End With 
Else 
End If 

Function PingSite(myWebsite) 
    Dim intStatus, objHTTP 

    Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") 

    objHTTP.Open "GET", "http://" & myWebsite & "/", False 
    objHTTP.SetRequestHeader "User-Agent", _ 
     "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)" 

    On Error Resume Next 

    objHTTP.Send 
    intStatus = objHTTP.Status 

    On Error Goto 0 

    If intStatus = 200 Then 
     PingSite = True 
    Else 
     PingSite = False 
    End If 

    Set objHTTP = Nothing 
End Function 

错误是。

回答

4

你昏暗bStrm,但初始化endbStrm

dim bStrm: Set endbStrm = createobject("Adodb.Stream") 

证据:

>> Dim x 
>> With x 
>> .Type = 1 
>> End With 
>> 
Error Number:  424 
Error Description: Object required 
>> 

使用Option Explicit避免这种失误。