问题
Ok, so I was going to make a neat program that made your Number Lock, Caps Lock, and Scroll Lock keys flash. My problem is when I run it, it only produces one number, instead of multiple ones that are different, any ideas as to what the problem might be?
Set Keys = WScript.CreateObject("WScript.Shell") 'So The Script Can Press keys
Dim MAX, MIN 'Declaration
MAX = 2 'Sets MAX Equal To 2
MIN = 0 'Sets MIN Equal To 0
Randomize 'So The Numbers Are Different All The Time
Number = (Int((MAX-MIN+1)*Rnd+MIN)) 'Assigns The Random number To A Variable
Do Until X = 10 'Does The Loop 10 Times
Select Case Number
Case 0 'If Number = 0 Then The Following happens
WScript.Sleep 500 'Stops The Script For 500 Milliseconds
Keys.SendKeys("{NUMLOCK}") 'Pushes The Number Lock
Case 1 'If Number = 1Then The Following happens
WScript.Sleep 500 'Stops The Script For 500 Milliseconds
Keys.SendKeys("{CAPSLOCK}") 'Pushes The Caps Lock
Case 2 'If Number = 2 Then The Following happens
WScript.Sleep 500 'Stops The Script For 500 Milliseconds
Keys.SendKeys("{SCROLLLOCK}") 'Pushes The Scroll Lock
End Select
X = X + 1 'Increment
Loop
回答1:
Posting comment as answer...
Well, for starters, you might want to put your equation within the loop so it regenerates the random number after every loop.
回答2:
You need to create the random number in the loop:
Do Until X = 10 'Does The Loop 10 Times
Number = (Int((MAX-MIN+1)*Rnd+MIN)) 'Assigns The Random number To A Variable
Select Case Number
来源:https://stackoverflow.com/questions/23814335/only-making-one-number-instead-of-a-number-between-0-and-2-multiple-times