表紙へ

テキストボックス

8.フォーカスを移動させない

 

以下のどのサンプルを実行するにもVB6が必要。

 

1.単純な例

 

Private Sub Text1_Validate(Cancel As Boolean)

    Cancel = True

End Sub

 

2.数値以外のものが入力された場合にフォーカスを移動させない例

 

Private Sub Text1_Validate(Cancel As Boolean)

    If Not IsNumeric(Text1.Text) Then

        Cancel = True

    End If

End Sub

 

メモ:わかりやすさを重視するためによく上のようなサンプルを書くが、私が自分用にプログラムするときはいつも次のようにしている。

Private Sub Text1_Validate(Cancel As Boolean)

    Cancel = Not IsNumeric(Text1.Text)

End Sub