View Single Post
  #1 (permalink)  
Old April 22nd, 2009, 06:43 AM
Tandy1000SL GW-BASIC Tandy1000SL GW-BASIC is offline
Authorized User
 
Join Date: Apr 2009
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Question 2 Separate Questions For The Same Code

The purpose of this Code is to test the Random Number Generation Process. I am not interested in going through 5 different Message Boxes; but, want all 5 Generated Random Numbers to be listed within the same Message Box.

I want the Random Numbers Generated to be different each and every time this Code is RUN.

I have been successful in generating a different sequence of Random Numbers during each Runtime; but, I haven't been successful at displaying the 5 Random Numbers Generated within a single Message Box.

QUESTION #1
?Why does the following Code only produce 4 Random Numbers instead of 5 within the Message Box?

?What do I need to do so that the Message Box shows all 5 Random Numbers?

Code:
 
'FILENAME:  DateTime.vbs     PROGRAMMING LANGUAGE:  Visual BASIC Script
'COMPUTER PROGRAMMING LANGUAGE PLATFORM:  Compaq Armada 1750 Windows Script Host (Windows 2000 Professional)
'AUTHOR/S:  Steven T. Querin
'CREATED ON:  3 April 2009     EDITED ON:  21 April 2009
 
' V I S U A L   B A S I C   S C R I P T   P R O G R A M M I N G   N O T E S
 
' A U T H O R ' S   N O T E S   &   E D I T I N G   N O T E S
 
' D E C L A R E D   V A R I A B L E S   &   C O N S T A N T S
Dim dtmSeed     'Randomized Seed Number based on the Date/Time Functions
Dim Number1     'numbers generated by Rnd Function
Dim Number2     'numbers generated by Rnd Function
Dim Number3     'numbers generated by Rnd Function
Dim Number4     'numbers generated by Rnd Function
Dim Number5     'numbers generated by Rnd Function
Dim Randomizer     'Variable used for calling Random Number Generator Procedures
 
' D A T E T I M E . V B S   M A I N   P R O G R A M
dtmSeed = Time
MsgBox dtmSeed & vbNewLine & "Hour = " & Hour(dtmSeed) & vbNewLine & "Minute = " & Minute(dtmSeed) & vbNewLine & _
  "Second = " & Second(dtmSeed)
 
dtmSeed = Time
Randomize[Second(dtmSeed)]
Number1 = Rnd
Number2 = Rnd
Number3 = Rnd
Number4 = Rnd
Number5 = Rnd
MsgBox dtmSeed & vbNewLine & vbNewLine & Number1 & vbNewLine & Number2 & vbNewLine & Number3 & vbNewLine & Number4 & _
  vbNewLine & Number5
 
' D A T E T I M E . V B S   P R O C E D U R E S
 
' S E T U P . V B S   P R O C E D U R E S
QUESTION #2
?How can I convert the above Code into a Single-Dimension Array?

VBScript Third Edition shows a Single-Dimension Array Example by listing 6 Colors in a Text Format. However, there is no example Single-Dimension Coding; or, any Downloaded FileNames for the Single-Dimension Array of the List Of Colors.

I have tried to use the following Code Lines; but, I get Error Messages during Runtime.

Code:
 
Dim dtmSeed
Dim Counter
Dim Number
Dim Number(Counter)
 
dtmSeed = Time
Randomize[Second(dtmSeed)]
For Counter = 1 to 5
     Number(Counter) = Rnd
Next     'Counter
MsgBox Number(1) & vbNewLine & Number(2) & vbNewLine & Number(3) & vbNewLine & Number(4) & vbNewLine & Number(5)
I would have zero problem with getting the above Code Sequences to work in GW-BASIC.

Also..."Dim Number" and "Dim Number(Counter)" were used in separate Coding Attempts; and, don't appear in the same Code together. I have the two together in the above Code Sample to reduce the amount of typing for this Posting.
Reply With Quote