View Single Post
  #2 (permalink)  
Old April 22nd, 2009, 05:58 PM
Old Pedant Old Pedant is offline
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

This is *NOT* legal VBScript code, so I have no idea how your code works, at all:
Code:
Randomize[Second(dtmSeed)]
VBscript does NOT use [...] for any purpose, whatsoever.

ALSO...

VBScript does *NOT* need an argument to RANDOMIZE. If you omit the argument, you get the best possible randomization. So you SHOULD omit it.

***************

In your second set of code, this line is illegal:
Code:
Dim Number(Counter)
First of all, you didn't assign any value to Counter before trying to use it. But in any case, VBScript does *NOT* allow an expression in DIMensioning an array.

You could (and, in this case, SHOULD) have simply coded
Code:
Dim Number(5)
and the code should have worked, excepting again for those bogus square brackets with Randomize.

******************

A much better/simpler way to have coded this would have been to recognize that in VBScript *ALL* arrays start at element 0 (not 1) and so you could have done simply:
Code:
Dim Counter
Dim Number(4)
 
Randomize
For Counter = 0 To UBound(Number)
     Number(Counter) = Rnd
Next 
MsgBox Join(Number,vbNewLine)
Reply With Quote