|
|
|
Forum MVP
      
Group: Forum Members
Last Login: 5/14/2012 4:43:58 PM
Posts: 728,
Visits: 2,932
|
|
The example script for the Random() function in the online E-Basic Help has two problems:
1) The example as provided only works with version 1.x, where you could copy & paste it all into a blank E-Run window. Since version 2 took away the ability to edit (or even view) source code, there is no way to run this example script as is in version 2 (but see below).
2) The example script does not even work in version 1.x, as it is missing definitions for the variables x, y, and message. It needs a line like
Dim x, y, message
in there somewhere, then it will work (I already tested this myself).
Of course, after adding a line to define the variables, if you just delete the "Sub Main()" and "End Sub" lines then it will work as inline script in either 1.x or 2. So for the sake of completeness, here is your Random() example with fixes applied (already tested by me in EP2):
'This example uses the random number generator to generate ten
'lottery numbers.
Const crlf = Chr$(13) + Chr$(10)
Dim x as Integer, y as Integer
Dim message as String
Randomize 'Start with new random seed.
For x = 1 To 10
y = Random(0,100) 'Generate numbers.
message = message & y & crlf
Next x
MsgBox "Ten numbers for the lottery: " & crlf & message
(Finally, if it were me I might not bother to define crlf and might instead use the predefined constant ebCR, which I also tested to work just fine. Oh, and I would follow established conventions and use i and j instead of x and y for arbitrary integer variables, but that's a programming style issue.)
Just thought you might like to fix this in future documentation.
-- David McFarlane, Professional Faultfinder
|
|
|
|
|
Forum MVP
      
Group: Forum Members
Last Login: 5/14/2012 4:43:58 PM
Posts: 728,
Visits: 2,932
|
|
Gosh, I had nicely indented that example with HTML non-breaking spaces, but when I previewed it the forum software stripped out my code and then I forgot to put it back in. So here it is again, with indentation:
'This example uses the random number generator to generate ten
'lottery numbers.
Const crlf = Chr$(13) + Chr$(10)
Dim x as Integer, y as Integer
Dim message as String
Randomize 'Start with new random seed.
For x = 1 To 10
y = Random(0,100) 'Generate numbers.
message = message & y & crlf
Next x
MsgBox "Ten numbers for the lottery: " & crlf & message
|
|
|
|