复制程式
Const Str1 As String = "abcdefghijklmnopqrstuvwxyz"
Private Sub Form_Load()
Dim R As Integer
Text1 = ""
Randomize
R = Fix(Rnd * 26) + 1
Label1 = Mid(Str1, R, 1)
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If LCase(Right(Text1, 1)) = LCase(Label1) Then
Dim R As Integer
Text1 = ""
Randomize
R = Fix(Rnd * 26) + 1
Label1 = Mid(Str1, R, 1)
End If
End Sub
正确来讲 [Caption]属性 是 [Label]物件类别 的[显示属性]...
就像 [TextBox]物件类别 的 [Text]属性 一样
然后VB的物件有个方便的功能就是物件名称能提取该物件最常用的属性
所以今天建立一个名称叫"Label1"的[Label]的物件
Label1.Caption = "test"
跟
Label1 = "test"
这两行的意思是一样的...
至于为什么CODE要写在KeyUp...试试下面的
复制程式
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Debug.Print "down event" & Text1
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Debug.Print "Press event" & Text1
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Debug.Print "up event" & Text1
End Sub
就会知道...当Press被引发的时候Text的内容是空的...
所以没办法判断输入的字元...