掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
TextBoxに数字しか入力するには? (ID:112265)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
この方法はどうですか? 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 これは入力桁数もチェックしてます。
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.