Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. catch for letters

catch for letters

Scheduled Pinned Locked Moved Visual Basic
csharptutorialquestionlearning
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Britnt7
    wrote on last edited by
    #1

    Does anyone know how to use an if statement in VB.Net to catch if a user enters a character instead of a number?:doh: The user should only be entering numbers in a textbox and if they enter a letter, I want to catch it. Thanks in advance:) Beginner in VB.Net

    L 1 Reply Last reply
    0
    • B Britnt7

      Does anyone know how to use an if statement in VB.Net to catch if a user enters a character instead of a number?:doh: The user should only be entering numbers in a textbox and if they enter a letter, I want to catch it. Thanks in advance:) Beginner in VB.Net

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Try the keypress event from the text box as below:

          Private Sub txtTitleLevel_KeyPress(ByVal sender As Object, _
          ByVal e As System.Windows.Forms.KeyPressEventArgs) _
          Handles txtTitleLevel.KeyPress
      
              If (e.KeyChar >= "0" And e.KeyChar <= "9") Or _
              e.KeyChar = Chr(8) Then
                  ' Chr(8) mean backspace.
                  e.Handled = False ' Allow user to input numeric value.
              Else
                  e.Handled = True ' Do not allow user to type character.
              End If
      
          End Sub
      

      A thousand mile of journey, begin with the first step. APO-CEDC Save Children Norway-Cambodia Office

      B 1 Reply Last reply
      0
      • L Lost User

        Try the keypress event from the text box as below:

            Private Sub txtTitleLevel_KeyPress(ByVal sender As Object, _
            ByVal e As System.Windows.Forms.KeyPressEventArgs) _
            Handles txtTitleLevel.KeyPress
        
                If (e.KeyChar >= "0" And e.KeyChar <= "9") Or _
                e.KeyChar = Chr(8) Then
                    ' Chr(8) mean backspace.
                    e.Handled = False ' Allow user to input numeric value.
                Else
                    e.Handled = True ' Do not allow user to type character.
                End If
        
            End Sub
        

        A thousand mile of journey, begin with the first step. APO-CEDC Save Children Norway-Cambodia Office

        B Offline
        B Offline
        Britnt7
        wrote on last edited by
        #3

        Thanks a million:-D Beginner in VB.Net

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups