Enter data into TextBox in VB6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • farhad
    New Member
    • Sep 2006
    • 17

    Enter data into TextBox in VB6

    Hi

    How can I control the TextBox that the user only able to enter Number to TextBox ? This meaning that the other keyboard keys be inactive to write.

    Thank you
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by farhad
    Hi

    How can I control the TextBox that the user only able to enter Number to TextBox ? This meaning that the other keyboard keys be inactive to write.

    Thank you
    Try this:

    Code:
    If Not IsNumeric(MyTextbox) Then
       MyTextbox = ""
       MsgBox "Only numbers please"
       MyTextbox.SetFocus
    End If

    Comment

    • willakawill
      Top Contributor
      • Oct 2006
      • 1646

      #3
      Why would you ask a question as vague as this and get a perfectly good reply as above then privately message me telling me that I don't know anything about programming. Do you think that this will encourage other community members to help you?

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by willakawill
        Try this:

        Code:
        If Not IsNumeric(MyTextbox) Then
           MyTextbox = ""
           MsgBox "Only numbers please"
           MyTextbox.SetFocus
        End If
        You could also try something along these lines...
        Code:
        Private Sub Text1_KeyPress(KeyAscii As Integer)
          If KeyAscii >= 65 And KeyAscii <= 90 Then
            Beep
            KeyAscii = 0
          End If
        End Sub
        This is a simplified version which just disallows uppercase letters. You can play with it to filter out other characters.

        Comment

        Working...