title: Look Ma, I can redefine global variables even with Option Explicit active -- but why?
body: <p>Here's one nice crazy discovery:</p>
  
  <pre><code>Option Explicit
  
  ExecuteGlobal "Option Explicit: Dim TestVar: TestVar=41"
  ExecuteGlobal "Option Explicit: TestVar=42"
  
  MsgBox "TestVar=" &amp; CStr (TestVar)
  </code></pre>
  
  <p>works as expected -- displays 42.</p>
  
  <p>And:</p>
  
  <pre><code>Option Explicit
  
  ExecuteGlobal "Option Explicit: TestVar: TestVar=41"
  
  MsgBox "TestVar=" &amp; CStr (TestVar)
  </code></pre>
  
  <p>yields "Undefined variable" in the ExecuteGlobal call since TestVar is not defined. <strong>OK.</strong></p>
  
  <p>What I do <em>not</em> understand is that this:</p>
  
  <pre><code>Option Explicit
  
  ExecuteGlobal "Option Explicit: Dim TestVar: TestVar=41"
  ExecuteGlobal "Option Explicit: Dim TestVar: TestVar=42"
  
  MsgBox "TestVar=" &amp; CStr (TestVar)
  </code></pre>
  
  <p>does <em>not</em> throw "Identifier redefined" in the second <code>ExecuteGlobal</code> call, but displays 42 -- as if the <code>Dim</code> in the second <code>ExecuteGlobal</code> call wasn't present.</p>
  
  <p>If you do the same with <code>Class</code> declarations, everything works fine, i.e. you cannot redefine a class under any circumstances.</p>
  
  <p><em>What the hell?</em></p>
  
  <p>My question is: <strong>Why does <code>ExecuteGlobal</code> allow me to redefine a global variable while a) ExecuteGlobal does forbid access to undeclared variables and b) class definitions are treated differently?</strong></p>
  
  <p>I do have a usecase that leads to this (generating source code at test runtime and executing it via ExecuteGlobal for some not-as-weird-as-you-might-expect reason), but the points I just made are valid enough without a description of the real-world secenario  I think.</p>
  
  <p>I came across this using QTP (HP QuickTest Professional), which uses the VisualBasic scripting host engine for script playback, but it is exactly the same situation in VB scripting host only.</p>