翻译VB代码

来源:百度知道 编辑:UC知道 时间:2024/05/14 10:52:29
Sub capt(ii As Integer)
S = "asdfghjklqwertyuiopzxcvbnm1234567890"
If (ii = 5) Then
For i = 0 To 4
i2 = Int(Rnd(Len(S) - 1) * Len(S) + 1)
ss = Mid(S, i2, 1)
Label1(i).Caption = ss
Next i

Else
i3 = Int(Rnd(Len(S) - 1) * Len(S) + 1)
ss = Mid(S, i3, 1)
Label1(ii).Caption = ss
End If
End Sub

Private Sub Command1_Click()
If Command1.Caption = "停止" Then
Command1.Caption = "继续"
Timer2.Enabled = False
Else
Command1.Caption = "停止"
Timer2.Enabled = True
End If
End Sub

Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)
For i = 0 To 4
If LCase(Trim(Label1(i).Caption)) = LCase(Chr(KeyCode)) Then
j = Int(Rnd(Form1.Width) * Form1.Width + 1)
Label1(i).Top = 0
Label1(i).Width = j
capt (i)
Label2.Caption = Int(Label2.Caption) + 1
End If
Next i
End Sub

P

Sub capt(ii As Integer) '自定义过程
S = "asdfghjklqwertyuiopzxcvbnm1234567890" '变量s值
If (ii = 5) Then '如果ii=5 则执行for循环
For i = 0 To 4
i2 = Int(Rnd(Len(S) - 1) * Len(S) + 1) '1到变量s字符长度区间随机选取一个数
ss = Mid(S, i2, 1) '从s里截取位置(随机数i2)的字符赋值给ss
Label1(i).Caption = ss 'ss值赋值给 标签
Next i

Else
i3 = Int(Rnd(Len(S) - 1) * Len(S) + 1) '同上
ss = Mid(S, i3, 1)
Label1(ii).Caption = ss
End If
End Sub

Private Sub Command1_Click()
If Command1.Caption = "停止" Then
Command1.Caption = "继续"
Timer2.Enabled = False
Else
Command1.Caption = "停止"
Timer2.Enabled = True
End If
End Sub

Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)
For i = 0 To 4
If LCase(Trim(Label1(i).Caption)) = LCase(Chr(KeyCode)) Then 'lcase转换大小写
j = Int(Rnd(Form1.Width) * Form1.Width + 1)
Label1(i).Top = 0