タイトルのままで失礼します。
VB6.0のTextBoxに、数字しか入力できなくする方法はありませんか?
先月に同じ事を答えましたが…
コピペされた時は駄目ですけど。
http://madia.world.coocan.jp/cgi-bin/VBBBS2/wwwlng.cgi?print+200402/04020077.txt
この方法はどうですか?
TextBoxのKeyPressイベントを使う方法です。
Private Sub txt1_KeyPress(Index As Integer, KeyAscii As Integer)
KeyAscii = KeyPressNum(KeyAscii, txt1, 5)
End Sub
Public Function KeyPressNum(KeyAscii As Integer, txtTarget As TextBox, nMaxLen As Long) As Integer
KeyPressNum = KeyAscii
Select Case KeyAscii
Case vbKeyBack, vbKeyEscape
Case 48 To 57 '0〜9
If LenB(StrConv(txtTarget.Text, vbFromUnicode)) - txtTarget.SelLength >= nMaxLen Then
KeyPressNum = 0
End If
Case Else
KeyPressNum = 0
End Select
End Function
これは入力桁数もチェックしてます。