When I wrote "QWERTY password: encryption and decryption" Yesterday, I wrote this For Next loop to get a string of 26 letters:
Copy codeThe Code is as follows: 'author: Demon
'Website: http://demon.tw
'Date: 2012/2/10
For I = 65 To (I + 25)
S = s & Chr (I)
Next
WScript. Echo s
After running the program, I found no string output, and thought it was strange. So I simply modified it:Copy codeThe Code is as follows: 'author: Demon
'Website: http://demon.tw
'Date: 2012/2/10
For I = 65 To (I + 25)
WScript. Echo Chr (I)
S = s & Chr (I)
Next
WScript. Echo s
There is still no output, which means that the statements in the For Next loop are not executed at all and cannot be understood. So I consulted the prophet Evening News, and he soon found the trap:Copy codeThe Code is as follows: 'author: Demon
'Website: http://demon.tw
'Date: 2012/2/10
For I = 65 To (I + 25) Step-1
WScript. Echo Chr (I)
S = s & Chr (I)
Next
WScript. Echo s
Finally, I believe that you will find the trap. The order of values For the For Next loop is not from left to right. The expression (I + 25) has been evaluated before I = 65, at this time, the I value is the default 0, so the original cycle is equivalent:Copy codeThe Code is as follows: 'author: Demon
'Website: http://demon.tw
'Date: 2012/2/10
For I = 65 To 25
S = s & Chr (I)
Next
WScript. Echo s
Of course there will be no output. Finally, I changed the program to this:Copy codeThe Code is as follows: 'author: Demon
'Website: http://demon.tw
'Date: 2012/2/10
For I = Asc ("A") To Asc ("Z ")
S = s & Chr (I)
Next
WScript. Echo s
It is straightforward and will not encounter the For Next trap.