From: vunet on
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
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

>
> 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
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
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.