Thursday, 04 January, 2001

More VBScript Wonkiness

Another page in the VBScript chronicles.  Today was a little frustrating, although ultimately rewarding because I finally got the entire system running on the test server.  The frustrating part was VBScript's wonkiness.  For example, I wrote this code to walk a record set:

CurrentID = rsSurvey("RespondentID")
while (not rsSurvey.EOF) and (CurrentID = rsSurvey("RespondentID")
  ' do processing

  ' move to next record
  rsSurvey.MoveNext
wend

All pretty standard stuff, except I got an exception when I tried to run it because VBScript doesn't shortcut its Boolean evaluation.  So even if the first test fails (i.e. EOF is true), it'll perform the second test.

There doesn't appear to be any way to break out of a while...wend loop (i.e. no break or exit while statement), so I ended up having to write the following code, which is reminiscent of my old ISO Pascal days (ISO Pascal also lacked shortcut Boolean evaluation):

CurrentID = rsSurvey("RespondentID")
bKeepGoing = not rsSurvey.EOF
while bKeepGoing = true
  ' do processing

  ' get next record
  rsSurvey.MoveNext
  if rsSurvey.EOF then
    bKeepGoing = false
  elseif CurrentID <> rsSurvey("RespondentID") then
    bKeepGoing = false
  endif
wend

My understanding is that the next version of VBScript fixes this and many other language oddities, although from what I hear the new language is quite different and existing applications probably won't compile.  I'm of two minds about that.  On one hand I'll be ticked off that I have to modify my programs to work with the new language.  But on the other hand, it appears that the new language was actually designed rather than just hacked together.  Maybe the new VBScript won't be so wonky.

Then again, maybe I'll just start writing my web apps in C#.