<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Some Quick Notes On Variable Scoping</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx</link><description>Here's a question I got a while back: In a VBS or ASP file, the following code doesn't work, which I understand: Option Explicit s = "hello" However, the following code works fine: Option Explicit s = "hello" Dim s Why can we use a variable before declaring</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Some Quick Notes On Variable Scoping</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx#159425</link><pubDate>Fri, 18 Jun 2004 17:19:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:159425</guid><dc:creator>grey</dc:creator><description>vb, javascript, etc. are not lexically scoped.&lt;br&gt;&lt;br&gt;at one point in time, i remember the following bombing out on me:&lt;br&gt;&lt;br&gt;Recurse(1, 10)&lt;br&gt;Function Recurse(current, stop)&lt;br&gt;  Dim interval&lt;br&gt;  interval = 1&lt;br&gt;  If current &amp;lt;= stop Then&lt;br&gt;    Recurse(current + interval, stop)&lt;br&gt;  End If&lt;br&gt;End Function&lt;br&gt;&lt;br&gt;The second time the function was called, it puked that the variable &amp;quot;interval&amp;quot; was already declared.&lt;br&gt;&lt;br&gt;This leads to showing that vb is not lexically scoped, and as such, I believe all Dims, etc. are pulled in first during runtime.  Hence why you have to do a ReDim at times.  It's a one-time declaration for a variable name for the entire life of the execution.</description></item><item><title>re: Some Quick Notes On Variable Scoping</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx#159434</link><pubDate>Fri, 18 Jun 2004 17:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:159434</guid><dc:creator>Eric Lippert</dc:creator><description>No, VBScript and JScript are lexically scoped.  (The &amp;quot;with' block in JScript leads to some dynamism in scope resolution, but lets ignore that for now.)&lt;br&gt;&lt;br&gt;Your program -- once I removed the four syntax errors -- compiles and runs just fine on my box.&lt;br&gt;&lt;br&gt;(For those following along at home: in a &amp;quot;lexically scoped&amp;quot; language, the binding between a variable name and the scope containing the variable can be determined from the compile-time text of the program.  In a &amp;quot;dynamically scoped&amp;quot; language, a given name can be bound to a different scope depending on runtime conditions.  Lisp is dynamically scoped.)&lt;br&gt;&lt;br&gt;&amp;gt;Hence why you have to do a ReDim at times&lt;br&gt;&lt;br&gt;No, redim resizes an array.  It doesn't redeclare a variable.&lt;br&gt;&lt;br&gt;I think you may be misremembering something, or have misinterpreted an error message somewhere along the way.  Can you give me an example of a VBScript program that shows the bad behaviour that you describe?&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Some Quick Notes On Variable Scoping</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx#159698</link><pubDate>Fri, 18 Jun 2004 22:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:159698</guid><dc:creator>Ricky Dhatt</dc:creator><description>Your link to ECMAScript 4 is mangled.  Maybe you meant: &lt;br&gt;&lt;a target="_new" href="http://www.mozilla.org/js/language/es4/core/definitions.html#hoist"&gt;http://www.mozilla.org/js/language/es4/core/definitions.html#hoist&lt;/a&gt; ?&lt;br&gt;&lt;br&gt;Since all I have been doing recently is application scripting with JScript, this is *great* stuff. Keep it up!</description></item><item><title>re: Some Quick Notes On Variable Scoping</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx#159699</link><pubDate>Fri, 18 Jun 2004 22:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:159699</guid><dc:creator>Eric Lippert</dc:creator><description>Fixed.  Thanks.&lt;br&gt;</description></item><item><title>re: Some Quick Notes On Variable Scoping</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx#169409</link><pubDate>Wed, 30 Jun 2004 03:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:169409</guid><dc:creator>Peter Torr</dc:creator><description>Oh boy, you don't want to know how many hours we spent talking about hoisting in ECMA meetings.</description></item><item><title>re: Some Quick Notes On Variable Scoping</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx#172407</link><pubDate>Sat, 03 Jul 2004 14:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:172407</guid><dc:creator>Bob Riemersma</dc:creator><description>I sure wish that &amp;quot;hoisting&amp;quot; had not been done in VBScript.  Not to be insensitive about it, but I could (almost) hardly care less what was done in JScript.  I'll save time by keeping my rant about &amp;quot;take a stab at what the coder meant&amp;quot; languages and language processors to myself.  The semicolon thing has been beat to death.&lt;br&gt;&lt;br&gt;My pain comes from all of the VBScript written by others that I've had to compile as VB6 over the years.  If only I'd taken the time to write something to automate the hoisting.  I already had a &amp;quot;grabber/packager&amp;quot; for the embedded literal HTML and the wrapping of &amp;quot;outer scope&amp;quot; code as Sub Page or whatever anyway.  So much for thinking (every time) that &amp;quot;this is the last time.&amp;quot;&lt;br&gt;&lt;br&gt;Oh well, such code invariably needs a lot of hand-tweaking anyway to get rid of bugs, dead code, and other absurdities.&lt;br&gt;&lt;br&gt;Still, how the heck did that philosophy ever get incorporated into VBScript?&lt;br&gt;&lt;br&gt;&lt;br&gt;BTW:  ReDim was always an odd creature.  Most bizarre to me was that it could be used in place of Dim, where I think it had a special significance in regard to storage allocation in the QB/PDS/VBDOS context.  Firing up VBDOS just now I see it's there all right.  Remember all that DGROUP vs. &amp;quot;far memory&amp;quot; stuff?  Thanks for nothing Intel.&lt;br&gt;&lt;br&gt;Then there's the seldom used (today) Erase statement... but I digress.</description></item><item><title>re: Some Quick Notes On Variable Scoping</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx#180888</link><pubDate>Mon, 12 Jul 2004 18:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:180888</guid><dc:creator>Eric Lippert</dc:creator><description>&amp;gt; Still, how the heck did that philosophy ever get incorporated into VBScript? &lt;br&gt;&lt;br&gt;The decision was before my time, and somewhat controversial at the time. I have always been opposed to it -- however, we're stuck with it now.&lt;br&gt;&lt;br&gt;And yeah, Redim and Erase are both a little weird.</description></item><item><title>conditional connection string | keyongtech</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx#9338153</link><pubDate>Sun, 18 Jan 2009 19:29:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9338153</guid><dc:creator>conditional connection string | keyongtech</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.keyongtech.com/1170065-conditional-connection-string"&gt;http://www.keyongtech.com/1170065-conditional-connection-string&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>ASP variable declaration bug or feature?! | keyongtech</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx#9362722</link><pubDate>Thu, 22 Jan 2009 07:34:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9362722</guid><dc:creator>ASP variable declaration bug or feature?! | keyongtech</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.keyongtech.com/1167032-asp-variable-declaration-bug-or"&gt;http://www.keyongtech.com/1167032-asp-variable-declaration-bug-or&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>