vb中接受回车键的问题

来源:百度知道 编辑:UC知道 时间:2024/05/21 17:04:35
我希望在vb中用do循环,循环到被按下回车为止。
具体的说就是,我想编一个程序 让它产生一个随即数 这个就像电视里的抽奖一样 数字不停的滚动。直到按下回车。请高手忙忙帮啊。
1楼的朋友你好。谢谢你的回答,不过我试过了那样不行。
我是这样写的
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Timer1.Enabled = True
End If
End Sub

Private Sub Form_Load()
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
m = Int(Rnd * 33 + 1)
Label1.Caption = Str(m)
End Sub

在窗体加一个text1把代码复制上去就行了,祝你好运
Dim b, a
Private Sub Form_KeyPress(KeyAscii As Integer)
b = KeyAscii
End Sub

Private Sub Form_Load()
Form1.KeyPreview = True
Show
Do Until a
If b = 13 Then Exit Do
Text1 = Trim(Str(Int(Rnd * 1000)))
DoEvents
Loop
End Sub

不要用do循环,用timer控件就行了,把timer1的enabled设为true,把要重复执行的语句放到timer1_timer中,然后把form的keypreview设为true,在form_keypress中加入:
if keyascii=13 then timer1.enabled=false
就行了。