Knowledge Base

PRB: No Error When Dimming a Variable That Already Has a Value

Article ID: 190271

Article Last Modified on 12/1/2003


APPLIES TO


This article was previously published under Q190271

SYMPTOMS

In VBScript, when a variable is dimmed that already has a value assigned to it, no error appears.

STATUS

This behavior is by design.

MORE INFORMATION

The following VBScript function, when executed, does not produce an error regarding duplicate declaration, on the statement "dim y".

Steps to Reproduce Behavior

sub test()
  y = 8    ' a value is assigned to y
  dim y    ' y is dimmed, this would cause an error in VBA
  msgbox y
end sub
				
In VBScript, this runs with no error. In Visual Basic for Applications (VBA), however, you get a compile error on the line "dim y" saying "duplicate declaration in current scope."

Additional query words: Error dim duplicate

Keywords: kbscript kbprb KB190271