Erattum: Random() example in online E-Basic Help
 
PST User Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



Erattum: Random() example in online E-Basic... Expand / Collapse
Author
Message
Posted 2/20/2009 11:33:30 AM
Forum MVP

Forum MVPForum MVPForum MVPForum MVPForum MVPForum MVPForum MVPForum 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
Post #2755
Posted 2/20/2009 11:57:45 AM
Forum MVP

Forum MVPForum MVPForum MVPForum MVPForum MVPForum MVPForum MVPForum 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
Post #2756
« Prev Topic | Next Topic »


Permissions Expand / Collapse

All times are GMT -5:00, Time now is 4:22am

Powered By InstantForum.NET v4.1.4 © 2012
Execution: 0.141. 7 queries. Compression Disabled.
 
Privacy | Terms of Use | Terms and Conditions | Legal Trademarks | Authorized Use | Quality Policy
Copyright 2012 Psychology Software Tools, Inc. All Rights Reserved
Email: Info@pstnet.com | Telephone: 412.449.0078 | Fax: 412.449.0079