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. How to create a text box that accepts only numbers and full stop in VB.Net

How to create a text box that accepts only numbers and full stop in VB.Net

Scheduled Pinned Locked Moved Visual Basic
csharphelptutorial
7 Posts 5 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.
  • T Offline
    T Offline
    tiagu
    wrote on last edited by
    #1

    I need help to create a text box that accepts only numbers and full stop in VB.Net.   It was easy in vb6 but in VB.Net I am really confused.   Can someone help me please, Thank you.

    D D J K 4 Replies Last reply
    0
    • T tiagu

      I need help to create a text box that accepts only numbers and full stop in VB.Net.   It was easy in vb6 but in VB.Net I am really confused.   Can someone help me please, Thank you.

      D Offline
      D Offline
      DidiKunz
      wrote on last edited by
      #2

      You need to handle the KeyPress Event[^] like you did with vb6. Reagrds: Didi

      1 Reply Last reply
      0
      • T tiagu

        I need help to create a text box that accepts only numbers and full stop in VB.Net.   It was easy in vb6 but in VB.Net I am really confused.   Can someone help me please, Thank you.

        D Offline
        D Offline
        dan sh
        wrote on last edited by
        #3

        How about using NumericUpDown control? (I guess you are allowing '.' for user to enter decimal numbers.)

        जय हिंद

        1 Reply Last reply
        0
        • T tiagu

          I need help to create a text box that accepts only numbers and full stop in VB.Net.   It was easy in vb6 but in VB.Net I am really confused.   Can someone help me please, Thank you.

          J Offline
          J Offline
          Johan Hakkesteegt
          wrote on last edited by
          #4

          Private Sub txt1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txt1.KeyPress
          Try
          If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then e.Handled = True
          Catch ex As Exception
          MsgBox(ex.ToString)
          End Try
          End Sub

          My advice is free, and you may get what you paid for.

          T 1 Reply Last reply
          0
          • J Johan Hakkesteegt

            Private Sub txt1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txt1.KeyPress
            Try
            If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then e.Handled = True
            Catch ex As Exception
            MsgBox(ex.ToString)
            End Try
            End Sub

            My advice is free, and you may get what you paid for.

            T Offline
            T Offline
            tiagu
            wrote on last edited by
            #5

            Thank you very much Johan,   Actually i wanted the box along with dots inbetween the numbers and I added IsPunctuation to your code.   Thank you once again. Didi, I was trying to do it as in vb6 but it was driving me mad without an answer.   Ofcourse I am a beginer in VB.Net and Johan's coding is very new to me.   Danish, thanks for your reply but I needed a box with numeric values and with / without decimals to be keyed in. Thank you all. :)

            J 1 Reply Last reply
            0
            • T tiagu

              Thank you very much Johan,   Actually i wanted the box along with dots inbetween the numbers and I added IsPunctuation to your code.   Thank you once again. Didi, I was trying to do it as in vb6 but it was driving me mad without an answer.   Ofcourse I am a beginer in VB.Net and Johan's coding is very new to me.   Danish, thanks for your reply but I needed a box with numeric values and with / without decimals to be keyed in. Thank you all. :)

              J Offline
              J Offline
              Johan Hakkesteegt
              wrote on last edited by
              #6

              If you are used to VB6, you'll find .NET a bit confusing in the beginning, because its approach is just a little different, however just like in the example code I showed you, check out all the new properties and methods. Lots of things have become much easier to do, and I am quite sure you'll come to love it in about two weeks time, and wonder how you managed to do it all with vb6.

              My advice is free, and you may get what you paid for.

              1 Reply Last reply
              0
              • T tiagu

                I need help to create a text box that accepts only numbers and full stop in VB.Net.   It was easy in vb6 but in VB.Net I am really confused.   Can someone help me please, Thank you.

                K Offline
                K Offline
                Kschuler
                wrote on last edited by
                #7

                The KeyPress code that you were given will work, just remember that if a user pastes a value into the textbox, the keypress code isn't going to stop the alpha characters like usual. It will still be possible for alpha values to get into the textbox, and you may have to add code to check for it. Just thought I'd mention it, since I've encountered that issue before.

                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