1、lacel1
2、text1
3、Command1
隨機數字產生在
lacel1控件裏面
text1
輸入隨機數字
Command1
單擊時驗證隨機數
具體代碼如下
Dim
txt
As
String
'全局變量txt為字符型
Private
Sub
Form_Load()
' 加載模塊時label1.caption
會變成壹個隨機1000
-
9999
的數字
Randomize
txt
=
Int(Rnd
*
(9999
-
1000
+
1)
+
1000)
'寫出1000
-
9999
的隨機數字
Label1.Caption
=
txt
End
Sub
Private
Sub
Label1_Click()
點擊時label1.caption
會刷新成壹個隨機1000
-
9999
的數字
Randomize
txt
=
Int(Rnd
*
(9999
-
1000
+
1)
+
1000)
'寫出1000
-
9999
的隨機數字
Label1.Caption
=
txt
End
Sub
Private
Sub
Command1_Click()
'單擊command1_click()
時
驗證隨機數
If
Text1.Text
=
txt
Then
MsgBox
"驗證正確"
End
If
End
Sub