Sign in to follow this  
Followers 0
cyanidemonkey

XML object error

4 posts in this topic

When I run this code below and there is no internet connection I get an no object error when the code reaches the For loop.

I'd like a more user friendly way of saying there is no net connection, how do I do this with the xml object?

Func _GetIP()
    Local $xmldoc = ObjCreate('Microsoft.XMLDOM'), $ip
    If Not IsObj($xmldoc) Then Return -1
    $xmldoc.async = False
    $xmldoc.load ('http://www.ippages.com/xml/')
    For $x In $xmldoc.documentElement.childNodes
        If $x.NodeName = "ip" Then
            $ip = $x.text
            ExitLoop
        EndIf
    Next
    $xmldoc = 0
    Return $ip
EndFunc

My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Share this post


Link to post
Share on other sites



Idea #1: If you check how many $xmldoc.documentElement.childNodes there are, won't they be zero where the connection is down?

Idea #2: How about in COM error handling code?

Idea #3: How about a valid value for @IPAddress1?

Share this post


Link to post
Share on other sites

When I run this code below and there is no internet connection I get an no object error when the code reaches the For loop.

I'd like a more user friendly way of saying there is no net connection, how do I do this with the xml object?

Func _GetIP()
    Local $xmldoc = ObjCreate('Microsoft.XMLDOM'), $ip
    If Not IsObj($xmldoc) Then Return -1
    $xmldoc.async = False
    $xmldoc.load ('http://www.ippages.com/xml/')
    For $x In $xmldoc.documentElement.childNodes
        If $x.NodeName = "ip" Then
            $ip = $x.text
            ExitLoop
        EndIf
    Next
    $xmldoc = 0
    Return $ip
EndFunc
Try this line it seems to work for me as the $xmldoc.load returns a -1 on sucess, 0 on failure:

Dim $RetVal 
$RetVal = $xmldoc.load ('http://www.ippages.com/xml/')
If $RetVal <> -1 Then
Return ("No Connection")
EndIF

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0