
INFO: Converting VBScript to VB.NET::Variable Allocation and Typing
Porting
VBScript to VB.NET for special purposes is possible. I've been looking
at some of the details of how code ports, and have some notes on this that may
be of interest.
One of the cornerstones of scripting is the ability to enforce explicit variable
allocation (via Option Explicit), but allow dynamic typing of variables.
It turns out that this works fine in VB.NET, using the default option settings.
There are two option declarations in VB.NET, covering making variable allocation
explicit (Option Explicit On) and making variable typing strict (Option Strict
On).
For classic VBScript requiring pre-allocation, the initial option settings
should be
Option Explicit On
Option Strict Off
With Strict "Off" you are not required to set a type; thus statements like the
following
dim a, b(), c
a = 9
a = "this is a string"
ReDim b(4)
work ok.
There are some issues with the methods we normally use to check and explicitly
cast types, but type coercion behaves almost identically.
--
Please respond in the newsgroup so everyone may benefit.
http://www.*-*-*.com/
(email requests for support contract information welcomed)
----------
Subscribe to Microsoft's Security Bulletins:
http://www.*-*-*.com/