If you see the -1 as return code the XMLHttp object has thrown an exception. But this is an error on the ActiveX side and you won't get much information in OpenOffice Basic about this exception of the ActiveX object.
But you need this error details, otherwise you don't know what you are supposed to fix or change. The only logical step that you have left is to execute the same methods of the ActiveX object in a different environment where you have the chance to get some further information. The Windows Scripting Host and the Powershell can serve for this purpose.
Visual Basic Script differs only in some details from the Basic interpreter of OpenOffice. Thus create a file testHttp.vbs:
- Code: Select all Expand viewCollapse view
Dim oHttp
Dim sUrl
Set oHttp = CreateObject("Microsoft.XmlHttp")
WScript.Echo getStatusOfUrl( oHttp, "http://www.postelnoe.vn.ua/index.php/percal/view/category/virtuemart_category_id/208")
WScript.Echo getStatusOfUrl( oHttp, "http://www.postelnoe.vn.ua/index.php/percal/view/productdetails/virtuemart_product_id/697/virtuemart_category_id/208")
Function getStatusOfUrl( http, sUrl)
On Error Resume Next
http.open "GET", sUrl, FALSE
http.send ""
If Err.Number <> 0 Then
WScript.Echo Err.Source & " (" & CStr(Err.Number) & ") " & Err.Description & ": Failure to retrieve " & sUrl
Err.Clear
getStatusOfUrl = -1
Else
getStatusOfUrl = http.status
End If
End Function
VBScript has a significant limitation compared to its big brothers Visual Basic and Visual Basic for Applications: You can't specify the type of variables and
On Error Goto SomeJumpMark is not supported. If you want to avoid that an error aborts your script you can only use
On Error Resume Next. As you know from my last post this means that you have to check the return codes of any statement and make sure that they have successfully done what they are supposed to do. The good thing is that VBScript has an global error object
Err where all well behaved ActiveX objects leave their failure conditions if they have run into a runtime error. The above code inspects this error object for details.
It might be interesting for you to learn to know that my tests to the
www.postelnoe.vn.ua URLs failed in the first run with -1, but returned a successful 200 when I executed the script a second time. Ah right, to execute this VBScript you need to open a command prompt and type:
cscript testHttp.vbs
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.