When I do server-side, I do ASP. Without the dot and NET. All my life I seem to be tied up to Win-based web servers and since I was never much of the programmer type, this was sufficient for my needs. And where is ASP, there is VBScript. Very simple, easy to learn, easy to work with.
The only thing I sorely missed in VBScript are associative arrays. In case you don’t know, in ordinary array, (in e.g.) third element is fetched by
2 is the integer index of the element. In associative arrays, index can be anything you like; e.g.
These arrays are extremely handy, especially when one deals with code lists, or reading username/user-details pairs from the database that needs to be stored into drop-down box etc. But they are not implemented in VBScript. There is
Scripting.Dictionary, but this is not a native VBScript object thus I use it only when necessary.
So, in the latest project I’m working on, I decided to develop the site using ASP-JScript combination, solely because of assoc. arrays. I was ready to re-write entire code libraries I used for years, learn new stuff, waste time looking for practically non-existing documentation etc - all because of opportunity to have those arrays.
Unfortunately, it’s all thorns, no roses. Two things made me gave up the whole idea and return to VBScript.
One of the best ASP practices when working with database connections is open late/close early approach. You open the connection object just before you need to make a database call, and close it as soon as possible afterwards.
If I’m getting the recordset, I usually do the following sequence:
1 2 3 4 5 6 7 8 9
Third line is there to disconnect the recordset, and then I can free the connection. Also, in the fifth line, I use the
Nothing keyword to remove the object from the memory.
However, in JScript, there is no way to do this. There is no equivalence to this keyword. MS MVP’s recommend to do this:
1 2 3 4 5 6 7 8 9
and then to call this function from your JScript code. I didn’t like at all, but I settled for it.
Then came the second problem. In VBScript, I could easily do this:
1 2 3
What this actually does is creates the
ADODB.Command Parameter on the fly and immediately adds it to
Command object. Afterwards, I can refer to that parameter by its name:
In JScript, this call-by-name is not possible. I need the reference to the object
CreateParameter returns and then use
Parameter.Value syntax. This is very unfortunate as the first approach allows for the creation of the wrapper function which can contain complete error handling for the parameter creation and adding to command, without the need to pass the parameter reference back to the calling page.
Even if I wanted to pass that reference back (from the function), I can do it in VBScript using the
ByRef keyword. However, not even this is possible in JScript. The JScript documentation explicitly states:
Even though objects and arrays are passed by reference, if you directly overwrite them with a new value in the function, the new value is not reflected outside the function.
That was the one drop too much. It’s almost as if Microsoft wanted to keep us away from JScript. I wonder if anyone of you did anything overly serious with ASP/JScript combination…