阿杰 发表于 2007-2-9 16:59:13

限制TextBox只能输入数字

Sub Text1_KeyPress(KeyAscii As Integer) <br/>If KeyAscii &lt; 48 Or KeyAscii &gt; 57 Then <br/>KeyAscii = 0 <br/>End If <br/>End Sub

马大哈 发表于 2007-2-9 17:45:23

<p>这样的话,还是可以复制粘贴的.</p><p>我前段时间在CSDN里发过一个,如下,应该是可以的了:</p><p>Private Sub Text1_Change()<br/>&nbsp;&nbsp;&nbsp; Dim I As Long, J As Long<br/>&nbsp;&nbsp;&nbsp; Dim K As String<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; For I = 1 To Len(Text1.Text)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; J = Asc(Mid(Text1.Text, I, 1))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If (J &gt; 48 And J &lt; 57) Or J = 46 Or J = 8 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K = K &amp; Chr(J)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Next I<br/>&nbsp;&nbsp;&nbsp; Text1.Text = K<br/>End Sub</p><p>Private Sub Text1_KeyPress(KeyAscii As Integer)<br/>&nbsp;&nbsp;&nbsp; If (KeyAscii &lt; 48 Or KeyAscii &gt; 57) And KeyAscii &lt;&gt; 46 And KeyAscii &lt;&gt; 8 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; KeyAscii = 0<br/>&nbsp;&nbsp;&nbsp; End If<br/>End Sub<br/></p>

dabian001 发表于 2007-2-10 12:07:12

0跟9 输入不了啊
页: [1]
查看完整版本: 限制TextBox只能输入数字