JScript and VBScript Arrays

    Earlier I alluded to the fact that JScript arrays are objects but VBScript arrays are not.  What’s up with that?   It’s kind of strange.  Consider the properties of a JScript array.  A Jscript array is   * one dimensional. * associative; JScript arrays are indexed by strings.  Numeric indices are actually converted…

17

Why does VBScript have Execute, ExecuteGlobal and Eval?

JScript has an extremely powerful (and almost always misused, but that’s another story) feature: eval takes a string at runtime and treats that string as though it were part of the compile-time text of the program.  I added that feature to VBScript version 5, but I did it with three methods: Execute, ExecuteGlobal and Eval. …

5

Why is it a bad idea to put script objects in Session scope?

Often a web site will have a series of related pages requested one after the other by the same user.  As a convenience for the site developers, the ASP object model provides a Session object to store server-side state for a current user.  It also has a global “Application” object which stores state for an…

7

How Do The Script Garbage Collectors Work?

UPDATE: This article was written in 2003. Since that time the JScript garbage collector has been completely rewritten so as to be more performant in general, to handle the larger working sets entailed by modern web applications that we had absolutely no idea were coming when we designed the JScript GC back in 1995, to be better at…

81

Why do the script engines not cache dispatch identifiers?

You COM programmers out there are intimately familiar with the IDispatch interface, I’m sure.  To briefly sum up for the rest of you, the point of IDispatch is that it allows a caller to call a function without actually knowing at compile time any details about the name or signature of that function.  The caller…

4

Eric’s Complete Guide To VT_DATE

I find software horology fascinating. The other day, Raymond said “The OLE automation date format is a floating point value, counting days since midnight 30 December 1899. Hours and minutes are represented as fractional days.” That’s correct, but actually it is a little bit weirder than that. I suspect that I may be the world’s…

11

What are the VBScript reference semantics for object members?

Clearly in order for VBScript to support variable referencing there has to be a variable to reference.  Consider our earlier example:   Sub Change(ByRef XYZ)    XYZ = 5 End Sub Dim ABC ABC = 123 Change ABC   If that had been  Change (ABC) then, based on what you know from two posts ago,…

10

More On ByRef vs ByVal

In my previous entry I discussed VBScript’s various syntaxes for passing values by reference.  However it occurs to me that there may be some confusion about what exactly “byref” and “byval” mean in JScript and VBScript.  This is frequently a source of confusion, as VBScript has byref behaviour not supported by JScript. The confusion arises…

7

What do you mean "cannot use parentheses?"

Every now and then someone will ask me what the VBScript error message “Cannot use parentheses when calling a Sub” means. I always smile when I hear that question. I tell people that the error means that you CANNOT use PARENTHESES when CALLING a SUB — which word didn’t you understand? Of course, there is…

56

Why does JScript have rounding errors?

Try this in JScript: window.alert(9.2 * 100.0); You might expect to get 920, but in fact you get 919.9999999999999.  What the heck is going on here? Boy, have I ever heard this question a lot. Well, let me answer that question with another question.  Suppose you did a simple division, say window.alert(1.0 / 3.0); Would…

7