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. textbox.......

textbox.......

Scheduled Pinned Locked Moved Visual Basic
4 Posts 3 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.
  • M Offline
    M Offline
    manni_n
    wrote on last edited by
    #1

    what coding do i do so that my textbox take values only between two integers say 0 to 45, any value other than this range gives error.. thanks

    T M 2 Replies Last reply
    0
    • M manni_n

      what coding do i do so that my textbox take values only between two integers say 0 to 45, any value other than this range gives error.. thanks

      T Offline
      T Offline
      TwoFaced
      wrote on last edited by
      #2

      Try a NumericUpDown control. If that's not an option you could do this a few ways. For one, in the validating event you could check the value to see if it's okay. Unless you want to disable copy/paste you'll probably have to validate the entry here anyway. The other option would be in the keypress event. You could check if the keypress was a number, if it's not you wouldn't allow it. Secondly, if it's a digit and the current contents including the new digit is > 45 you could dissallow it. If you prevent '-', this would take care of anything less then 0 so you wouldn't really need to worry about it.

      1 Reply Last reply
      0
      • M manni_n

        what coding do i do so that my textbox take values only between two integers say 0 to 45, any value other than this range gives error.. thanks

        M Offline
        M Offline
        Mogtabam
        wrote on last edited by
        #3

        Hi You Can Use This Code. (Text1 is your TextBox) Private Sub Text1_Change() If Val(Text1.Text) > 45 Then Text1.Text = 45: MsgBox "Please Enter A Number Between 0 to 45", vbCritical End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 48 To 57: '0 To 9 Case 8: 'Back Space Case 13: 'Enter Case Else: 'Other Keys KeyAscii = 0 End Select End Sub Good Luck Mogtabam

        M 1 Reply Last reply
        0
        • M Mogtabam

          Hi You Can Use This Code. (Text1 is your TextBox) Private Sub Text1_Change() If Val(Text1.Text) > 45 Then Text1.Text = 45: MsgBox "Please Enter A Number Between 0 to 45", vbCritical End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 48 To 57: '0 To 9 Case 8: 'Back Space Case 13: 'Enter Case Else: 'Other Keys KeyAscii = 0 End Select End Sub Good Luck Mogtabam

          M Offline
          M Offline
          manni_n
          wrote on last edited by
          #4

          thanks people... for sending me solutions... regards.. manni

          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