From: Bob Barrows on 17 Feb 2010 15:05 vunet wrote: > 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. Well, it's kind of a contradiction in terms. Declaring a variable is done via a Dim statement: Dim myvar Declaring it outside of a procedure gives it "global" scope. Declaring it withing a procedure limits its scope to that procedure. So, the statement you are describing would be more correct if it said "it is not possible to declare global variables within a function", and the language is irrelevant. I believe your misunderstanding stems from incorrectly applying the term "declare" to the Set statement, which assigns an object to a variable. That said, in vbscript, there is no need to explicitly declare variables. The first reference to a variable essentially declares it. So I can see where you might make the mistake of thinking the Set statement declares the variable. Anyways, to avoid confusion, you should always use OPTION EXPLICIT at the beginning of your pages, which forces you to explicitly declare your variables. It will become quickly obvious that global variables cannot be declared within procedures (subs or functions). Here is some fun reading: http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx http://blogs.msdn.com/ericlippert/archive/2003/09/20/53058.aspx -- 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"
First
|
Prev
|
Pages: 1 2 Prev: Msxml2.ServerXMLHTTP and Time Out Next: Different versions of ASP in the same iis process |