一、创建数组
二、随机数字存进去
三、for循环判断数组参数是否重复
四、随机数转换成按键
五、查询按键ASCIIma并用for输出数组
下面一图为按键精灵转换后的语言:
下面是TXT中 :
- **Dim RndNum(11)
Dim n, i, m, Result
'初始化数组
For i = 0 To 11
RndNum(i) = 0
Next
'生成1-12随机数
n = 0
Randomize
RndNum(0) = Int(12 * Rnd + 1)
While n < 11
Result = 0 '随机数重复标志,0表示不重复,1表示重复
Randomize
m = Int(12 * Rnd)
'For循环判断生成随机数是否和前面重复
For i = 0 To n
If m = RndNum(i) Then
Result = 1
End If
Next
If Result = 0 Then
n = n + 1
RndNum(n) = m
End If
Wend
'把随机数转换成按键
For i = 0 To 11
'MessageBox RndNum(i)
If RndNum(i) = 10 Then
RndNum(i) = 107
ElseIf RndNum(i) = 11 Then
RndNum(i) = 109
Else
RndNum(i) = RndNum(i) + 96
End If
Next
'数组RndNum存放结果,下面这一句是查看按键ASCII码的
MessageBox Join(RndNum, “|”)
'依次按键
For i = 0 To 11
KeyPress RndNum(i), 1**