2015-10-20 92 views
0

確定代碼正常工作。它得到一個號碼,然後傳送,要一個字母(1=a,2=b,3=c,etc...),但它似乎是重複的字母比它應該例如它說這個我的Vbscript似乎有一些未知的錯誤,但工作正常嗎?

輸出更多:

 

    fffqqqqqqvxquukgggdrsp!biiirsssx!!xxrrrrghddaaayyvvtttjdeexxxvvvzzeuzz!u zzzzqp..qxxxttg!feeeee,,,,, 

它隨機選擇這些字符,但在實際的代碼中有68個,似乎太多的巧合,它應該經常重複這麼多。 Sendkeys是否可以在循環之前以某種方式重複自己?

下面的代碼:

Set ws = CreateObject("Wscript.Shell") 

Dim max 
max = InputBox("Max number of characters (Numbers Only!)", _ 
    "Enter Integer") 


If max = "" Then 
    Wscript.Quit 
elseif max < 0 Then 
    Wscript.Quit 
end if 

max = CInt(max) 

i = 0 

intAnswer = _ 
    Msgbox("Do you want to open a new Notepad?", _ 
     vbYesNo, "New Notepad") 

If intAnswer = vbYes Then 
    ws.Run "notepad.exe" 
End If 

Wscript.sleep 3000 

do while max > i 

i = i + 1 

Randomize 


rand = Int((3 - 1 + 1) * rnd + 1) 

    if rand = 1 then 
     char = "a" 
    elseif rand = 2 then 
     char = "b" 
    elseif rand = 3 then 
     char = "c" 
    elseif rand = 4 then 
     char = "." 
    elseif rand = 5 then 
     char = "," 
    elseif rand = 6 then 
     char = "!" 
    elseif rand = 7 then 
     char = "?" 
    elseif rand = 8 then 
     char = " " 
    elseif rand = 9 then 
     char = "{ENTER}" 
    end if 

    Wscript.sleep 75 
    ws.Sendkeys char 

    loop 

    Wscript.Quit 

回答

0

你似乎是一個和9

這樣做的正確的代碼之間的隨機數後

rand = Int(rnd * 9) + 1 

RND生成一個隨機任何地方在零和一。

+0

不要忘記['Randomize'](https://msdn.microsoft.com/en-us/library/38d7ckek(v = vs.84).aspx),否則種子不會改變。 – Lankymart

+0

恩沒對不起,但我忘了改變,問題是相同的字符正在重複,當我使用Sendkeys的,這是不正確的,以獲得隨機數它是隨機數 rand = Int((max - min + 1)* rnd + min)' – TheGamerLord

+0

那裏我只是修復了它 – TheGamerLord

相關問題