2010-04-18 97 views
-1
Private Sub Command1_Click() 
    Dim dom As New DOMDocument 
    Dim http As New XMLHTTP 
    Dim strRet As String 
    If Not dom.Load("c:\\CH.xml") Then MsgBox "文件不存在" 
    http.Open "Post", "http://172.31.132.173/u8eai/import.asp", True '指定服務器ASP 
    http.send dom.xml '把xml數據發送服務器端 
    strRet = http.responseText 'strRet:返回的xml格式的回執信息 
    MsgBox strRet 
End Sub 

The error message, in Chinese: 實時錯誤 完成該操作所需的數據還不可使用. translated by google(To English): Real-time error The data needed to complete the operation can not be used alsoI get a error message from my vb6 program

+1

What's the error number? ('Err.Number') That will be the same regardless of language, and would let you (and anyone trying to help you) find it on the MSDN site. – 2010-04-18 09:29:15

回答

1

("實時錯誤 完成該操作所需的數據還不可使用" means "Run-time Error, data for this operation is not usable yet.")

The problem is you're issuing the HTTP request as asynchronous

http.Open "Post", "http://172.31.132.173/u8eai/import.asp", True 

which means the send method will return immediately even before the server responses.

http.send dom.xml 

but before the server responses you're asking the responseText value already. Of course this will cause the runtime error.

strRet = http.responseText 

One workaround is to issue a synchronous request, i.e. change the 3rd parameter of http.open to False. A better method is set a handler of http 's to handle the readyStateChange event (consult the doc for detail).

+0

+1. Also, 'dom' object is being loaded asynchronously (use 'dom.async = False' to make it synchronous or check the 'dom.readystate' property). – GSerg 2010-04-18 09:46:45

+0

Really thank you. Vb6 is different from vb.net. – 2010-04-19 00:10:35

相關問題