Private Sub Text1_KeyPress(KeyAscii As Integer) '「1-9」[BackSpace]以外の入力はじき、5桁以上は入力不可 If Not IsNumeric(Chr$(KeyAscii)) And KeyAscii <> vbKeyBack And KeyAscii <> vbKeyDecimal Or _ (Len(Text1.Text) >= 4 And KeyAscii <> vbKeyBack And KeyAscii <> vbKeyDecimal) Then KeyAscii = 0 Else '全角を半角に変換する KeyAscii = Asc(StrConv(Chr$(KeyAscii), vbNarrow)) End If End Sub