VB 小问题,希望高手进来一下

来源:百度知道 编辑:UC知道 时间:2024/09/22 01:18:54
1、怎样让 Text1 只能输入数字
2、如果要在 Text1 中输入几个数字,再按一下命令按钮 Command1 就可以将 Text1 里的数字添加给另一个控件的属性上,比如添加给 Timer1 的Interval属性(Text1 是 Form2 里的控件,而 Timer1 是 Form1 里的控件)这要怎么办到,还请大家帮帮忙,谢谢了

第一个问题
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
MsgBox "只能为数字"
End If
End Sub

第二个问题
Private Sub Command1_Click()
Form1.Timer1.Interval = Val(Text1)
End Sub

Private Sub Command1_Click()
From1.Timer1.Interval = From2.Text1.Text
End Sub

Private Sub text1_KeyPress(KeyAscii As Integer)
If InStr(1, "0123456789.", UCase(Chr(KeyAscii)), 1) <= 0 And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub

定义个全局变量!
public i as intelger

程序这么写的
private sub com1
i=text1.text
endsub

private sub form1
timer1.interval=i
endsub

'Textbox text1 only type 0 to 9
Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If

End Sub

'Click