From: vunet on 17 Feb 2010 11:17 I'd like to set a global variable within a function not to set it every time when needed. However, this never works for me using Is Nothing check like so: set objXML = nothing function setAppXML () response.write "<br>objXML="&(objXML is nothing)&"<br>" <--always True <------------ if objXML is nothing then Set objXML = Server.CreateObject("Microsoft.XMLDOM") objXML.async = False setAppXML = objXML.Load (Server.MapPath("test.xml")) else setAppXML = true end if end function Please recommend a solution or advise. Thanks.
From: Bob Barrows on 17 Feb 2010 11:41 vunet wrote: > I'd like to set a global variable within a function not to set it > every time when needed. However, this never works for me using Is > Nothing check like so: > > set objXML = nothing > function setAppXML () > response.write "<br>objXML="&(objXML is nothing)&"<br>" <--always > True <------------ Oh course it is "always True" ... you have it outside of your if statement .... > if objXML is nothing then > Set objXML = Server.CreateObject("Microsoft.XMLDOM") > objXML.async = False > setAppXML = objXML.Load (Server.MapPath("test.xml")) > else > setAppXML = true > end if > end function > > Please recommend a solution or advise. Thanks. -- Microsoft MVP - ASP/ASP.NET - 2004-2007 Please reply to the newsgroup. This email account is my spam trap so I don't check it very often. If you must reply off-line, then remove the "NO SPAM"
From: vunet on 17 Feb 2010 12:17 > > Oh course it is "always True" ... you have it outside of your if statement > ... Sorry I was not clear. The objXML is declared outside of function to be global. I call setAppXML many times on the page below so I would not have to set the object (i.e. load XML) every time I call the function. So once it is set, it should be FALSE to Is Nothing but it is always TRUE.
From: Bob Barrows on 17 Feb 2010 12:37 vunet wrote: >> Oh course it is "always True" ... you have it outside of your if >> statement ... > > Sorry I was not clear. The objXML is declared outside of function to > be global. I call setAppXML many times on the page below so I would > not have to set the object (i.e. load XML) every time I call the > function. So once it is set, it should be FALSE to Is Nothing but it > is always TRUE. You're going to have to show us how to really reproduce your problem. The code you showed us will always result in the message objXML is nothing Create a new page, include nothing but the code that deals with objXML, make sure it reproduces your problem, then post it here. -- Microsoft MVP - ASP/ASP.NET - 2004-2007 Please reply to the newsgroup. This email account is my spam trap so I don't check it very often. If you must reply off-line, then remove the "NO SPAM"
From: vunet on 17 Feb 2010 13:21 I discovered the problem. I was setting it to Nothing at the end of another function. Sorry for confusion. However, while I was googling I found a statement where it says that global variables should not be declared within a function in VBScript. It's a bad thing to do and against the rules. Is it really true? Many thanks.
|
Next
|
Last
Pages: 1 2 Prev: Msxml2.ServerXMLHTTP and Time Out Next: Different versions of ASP in the same iis process |