投稿日 | : 2003/07/03(Thu) 16:19 |
投稿者 | : ナンバリ |
Eメール | : |
URL | : |
タイトル | : Re^3: 制御系なので |
以前どこかで参照させてもらったものですが、
下記の用なプログラムではだめでしょうか?
Private Sub Text1_KeyPress(KeyAscii As Integer)
Const Number$ = "-0123456789."
If KeyAscii <> 8 Then 'バックスペースは例外
If InStr(Number, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
Exit Sub
Else
If "." = Chr(KeyAscii) Then
If InStr(Text1.Text, ".") > 0 Then '「.」は一つだけ
KeyAscii = 0
Exit Sub
End If
End If
If "-" = Chr(KeyAscii) Then
If InStr(Text1.Text, "-") > 0 Then '「-」は一つだけ
KeyAscii = 0
Exit Sub
End If
End If
End If
End If
'入力チェック
if val(text1.text) >= 9999 then msgbox "上限を超えました"
End Sub
チェックをかけるのはコントロール配列の方が便利だと思います。