+ Reply to Thread
Results 1 to 1 of 1

Best practice for error-checking XML object instantiation?

Hybrid View

  1. #1
    Registered User
    Join Date
    02-20-2012
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    25

    Best practice for error-checking XML object instantiation?

    I have Excel VBA code that makes a SOAP call to a web service, and extracts the results from the XML response, then writes the values to WorkSheet cells. It was a long painful process, but eventually I got this working, and it appears fairly robust. However, I will soon be releasing this code to a larger user base (it's in limited release right now), and I'd like to add more "on error" error-handling to avoid any runtime errors.

    In particular, I need advice/help about adding error-handling to the code that uses selectSingleNode. I do check it afterward to ensure it's not empty, but obviously, that doesn't cover the situation in which there may be an error in the "Set objXmlNode..." statement. I'd like to keep the "if objXmlNode Is Nothing" code (if y'all think that makes sense). How can I add "on error" code to this code?

    	'...[more code here]
    	Dim objXmlHttp As MSXML2.XMLHTTP60
    	Static objXmlDoc As MSXML2.DOMDocument60
    	Dim objXmlNode As MSXML2.IXMLDOMNode
    	'...[more code here]
    	Set objXmlNode = objXmlDoc.selectSingleNode("//*[local-name()='commandExitCode' and namespace-uri()='ABC_IPAM:IPAM_methods']/text()")
    	If objXmlNode Is Nothing Then
    		bProvisionFailFlag = True
    		strCommandExitCode = "Nothing"
    		strProvisionerResultsMsg = strProvisionerResultsMsg & "ERROR: Unable to extract exit code from web service (i.e., objXmlNode is Nothing, commandExitCode node selection came up empty)" & vbLf
    	Else
    		strCommandExitCode = objXmlNode.Text
    	End If
    	'...[more code here]
    P.S. I already have "on error" code in place and tested for the instantiation of the MSXML2.XMLHTTP60 and MSXML2.DOMDocument60 objects, but omitted it here for brevity.
    Last edited by btmtdk; 10-07-2013 at 05:13 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 02-18-2013, 10:17 AM
  2. best practice on error handling formulas in VBA
    By WasWodge in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-29-2011, 05:35 PM
  3. Error Checking
    By dshilan in forum Excel General
    Replies: 1
    Last Post: 11-05-2010, 02:18 PM
  4. Error checking
    By Cbrehm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-15-2010, 07:25 PM
  5. [SOLVED] practice sessions won't download get error on page
    By big bear in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 06-14-2005, 03:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1