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. validating numbers in a textbox

validating numbers in a textbox

Scheduled Pinned Locked Moved Visual Basic
question
5 Posts 4 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
    Binary0110
    wrote on last edited by
    #1

    I'm writing a program that converts a number in a textbox from one metric unit to another. I need to write an if statement that will validate that what is in the textbox is a numer and if it isn't returns a message box. any suggestions with code samples would be appreciated. BINARY

    S C 2 Replies Last reply
    0
    • B Binary0110

      I'm writing a program that converts a number in a textbox from one metric unit to another. I need to write an if statement that will validate that what is in the textbox is a numer and if it isn't returns a message box. any suggestions with code samples would be appreciated. BINARY

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      Try the Parse method in the Int32 class. Something like

      Dim number as Int32
      Try
      number = Int32.Parse(textBox.Text)
      Catch
      // Show Messagebox here

      Regards Senthil _____________________________ My Blog | My Articles | WinMacro

      1 Reply Last reply
      0
      • B Binary0110

        I'm writing a program that converts a number in a textbox from one metric unit to another. I need to write an if statement that will validate that what is in the textbox is a numer and if it isn't returns a message box. any suggestions with code samples would be appreciated. BINARY

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Why not do it the smart way and use one of the many controls on this site that give you a text box which only accepts numbers ? Otherwise, I'd use a regular expression to pull a number out before I did a try/catch, that's just ugly. Christian Graus - Microsoft MVP - C++

        B 1 Reply Last reply
        0
        • C Christian Graus

          Why not do it the smart way and use one of the many controls on this site that give you a text box which only accepts numbers ? Otherwise, I'd use a regular expression to pull a number out before I did a try/catch, that's just ugly. Christian Graus - Microsoft MVP - C++

          B Offline
          B Offline
          Binary0110
          wrote on last edited by
          #4

          I ended up using IsNumeric to validate the textbox. Thanx all. BINARY

          D 1 Reply Last reply
          0
          • B Binary0110

            I ended up using IsNumeric to validate the textbox. Thanx all. BINARY

            D Offline
            D Offline
            devitj
            wrote on last edited by
            #5

            try this IsNumeric("$1") returns true this is wrong.

            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