wouterm wrote:Have been trying it in VBS now. There the ActiveX module does what is is supposed to do. But here I have run into another problem, getting VLOOKUP to work in Calc from VBS.
If I run the test in VBScript I get the opposite result as you: google.com returns a failure (probably because it tries to attempt a redirect to https.
yellow-box is a server in my internal network and the other one
www.bol.com is surely something you are more aware off than me.
Code: Select all
sUrl = "http://www.google.com/"
Set http = CreateObject("Microsoft.XmlHttp")
WScript.Echo getStatusOfUrl( http, sUrl)
WScript.Echo getStatusOfUrl( http, "http://yellow-box/")
WScript.Echo getStatusOfUrl( http, "http://www.bol.com/")
Function getStatusOfUrl( http, sUrl)
On Error Resume Next
'Load Webpage where address is URL
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
'Assign webpage contents as a string to variable called Webpage
sWebPage = http.responseText
End Function
This are the results:
Code: Select all
msxml3.dll (-2147024891) Zugriff verweigert: Failure to retrieve http://www.google.com/
-1
200
200
It seems like the http Response Code 302 (redirect) is converted into an exception by the ActiveX object. Hm, this is a really individualistic interpretation of a 3xx http status code. Surely not what the W3C consortium has intented with this status codes. Due to this strange interpretation of the http codes by the ActiveX/COM object it is essential to work with a language that supports exceptions by concept (Javascript, Python, Java) and not by work-around (Visual Basic, OOo Basic).
The
Err.Number test in my above code contradicts the concept of Exceptions as it reads again some kind of
return code from a function or method (although stored in a global variable/object).
The crucial idea with exception is:
If something is really exceptional, don't massage it until it fits into a return code variable, but "return" it through a completely different channel: throw an exception (object). It is an "exception" (something I haven't planned for), so why should it match with my concept/structure of return values!?
Conclusion: Don't use Basic if you have to deal with network I/O. If you use Python you will have enough tracing features to look under the hood of the network communications. Basic just leaves your alone here: Right, "Zugriff verweigert" is German, but even in a english OS version a "Access denied" wouldn't be helpful at that stage. Of course with some masochistic tendencies you might stick to Basic, but in that case be prepared that a network sniffer (tcpdump or wireshark) has to do the dirty work for you to see what you would have seen directly with the help of some tracing options directly in Python.
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.