Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time error '91' Object variable or With block variable not set

Status
Not open for further replies.

nondrinker

Programmer
Jan 23, 2002
53
US
Hello,
Below is the code that i am trying to use to read some data from of an xml file, using vb6. I have been getting this error: "Run-time error '91' Object variable or With block variable not set" on the line that i have pointed.

I have checked all the referneces and everything seems to be there.

Any help will be appreciated.
Thanks.

********************************************

Dim xmlas As MSXML2.DOMDocument
Set xmlas = New MSXML2.DOMDocument
Dim varstatus
Dim nodeAttribute
Dim objAttributes
Dim objRefAttr


xmlas.preserveWhiteSpace = True
xmlas.validateOnParse = True
xmlas.async = False
xmlas.Load ("Test.xml")


Set nodeAttribute = xmlas.selectSingleNode("//response[0]")
Set objAttributes = nodeAttribute.Attributes <-------This is where it breaks
Set objRefAttr = objAttributes.getNamedItem("cleintid")

varstatus = objRefAttr.Text
MsgBox varstatus

**********************************************
 
Most probably this.
>[tt]Set objRefAttr = objAttributes.getNamedItem("cleintid")
Set objRefAttr = objAttributes.getNamedItem("cl[red]ie[/red]ntid")[/tt]
 
Thanks for the correction.
I have corrected the spelling but still its erroring out
the same way and on the same line.
 
If the xml file does not have the clientid attribute anywhere, the vb ide will exhibit error 91 at that line exactly as you have mentioned, but on the .text line. So, I think I was not trying to just correct a typo if it really is one, it is a generic error of the same reason.

You use .validateonparse=true. Are you sure the xml file can be validated properly, else your subsequent objects can be nothing. Try actually capture the error like this.
[tt]
Set nodeAttribute = xmlas.selectSingleNode("//response[0]")
if not (nodeAttribute is nothing) then
Set objAttributes = nodeAttribute.Attributes
Set objRefAttr = objAttributes.getNamedItem("cleintid")
else
msgbox "Cannot find response node"
'go to some error handling
end if
[/tt]
Similarly you can device same kind of damage control if you cannot find any "clientid" attribute over the "response" nodes.
 
Ok, to check the validatiaon, i pasted the entire xml file at:and it told me No Error Found.

But in my code, as suggested by you, i have added the "Is Nothing" check and it keeps going to the else part, meaning it is not finding the nodeAttribute.
 
Validation is very much still implementation-dependent. If you parse with w3 engine, it is an indicator. You can for testing echo out the contents after the load line.
[tt] msgbox xmlas.xml[/tt]

>But in my code, as suggested by you, i have added the "Is Nothing" check and it keeps going to the else part, meaning it is not finding the nodeAttribute.
In that case, what do you say. Is it obvious for the way to check?
 
tsuji,
Thank you for your help.

Well for some reason my code was hanging on this line, with the same error:
**************************
varstatus = objRefAttr.Text
**************************

I changed the code to:
**************************
varClientId = xml.getElementsByTagName("clientid").Item(0).Text
**************************
and then it started working fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top