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. vb.net code question

vb.net code question

Scheduled Pinned Locked Moved Visual Basic
csharphelpquestion
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.
  • C Offline
    C Offline
    chippuppy
    wrote on last edited by
    #1

    I am new to the vb.net thing and am trying to self teach myself so any help is appreciated. I need to be able to make sure that a textbox entry is only numbers and that I can backspace it to remove a bad entry. I think its probably something like a bunch of ASCII characters to reference and valadate the entry but I am not sure. Sub Text_KeyPress(KeyAscii As Integer) If uiEnterInterNumTextBox.Text = KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0 and uiEnterInterNumTextBox.Text = KeyAscii End Sub

    F C 2 Replies Last reply
    0
    • C chippuppy

      I am new to the vb.net thing and am trying to self teach myself so any help is appreciated. I need to be able to make sure that a textbox entry is only numbers and that I can backspace it to remove a bad entry. I think its probably something like a bunch of ASCII characters to reference and valadate the entry but I am not sure. Sub Text_KeyPress(KeyAscii As Integer) If uiEnterInterNumTextBox.Text = KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0 and uiEnterInterNumTextBox.Text = KeyAscii End Sub

      F Offline
      F Offline
      FrankyT
      wrote on last edited by
      #2

      heres how I would do it. remember, in vb, try not to do it the hard way. most of the time you'll find an easy one. BTW somthing seems wrong with your keypress event handler, I'm used to Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress now if your working in vb 6 or VBA this code may not work. by the way if this is homework, at least paraphrase... geta little edu for your money. Sub Text_KeyPress(KeyAscii As Integer) If isAllNumbers(uiEnterInterNumTextBox.Text)Then KeyAscii = 0 uiEnterInterNumTextBox.Text = KeyAscii End If End Sub Private Function isAllNumbers(ByVal teststring As String) As Boolean Dim isgood As Boolean = True For Each c As Char In teststring If Not Char.IsDigit(c) and not(c = ".") and not( c = ",") Then isgood = False Exit For End If Next Return isgood End Function hey...slang is the vernacular for the vernacular...wow

      1 Reply Last reply
      0
      • C chippuppy

        I am new to the vb.net thing and am trying to self teach myself so any help is appreciated. I need to be able to make sure that a textbox entry is only numbers and that I can backspace it to remove a bad entry. I think its probably something like a bunch of ASCII characters to reference and valadate the entry but I am not sure. Sub Text_KeyPress(KeyAscii As Integer) If uiEnterInterNumTextBox.Text = KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0 and uiEnterInterNumTextBox.Text = KeyAscii End Sub

        C Offline
        C Offline
        Chatura Dilan
        wrote on last edited by
        #3

        Or You can use a MaskedTestbox to do it Or Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If (AscW(e.KeyChar) < 48 Or AscW(e.KeyChar) > 57) Then e.KeyChar = Nothing End If End Sub

        Regards,

        Chatura Dilan

        If at first you don't succeed, try; try again, so that you know what not to do the next time. The answer is out there. -- modified at 23:25 Tuesday 4th April, 2006 'sorry.. when you use e.KeyChar = Chr(Keys.Back), other keys always do backspace's job. I corrected it. It must be e.KeyChar = Nothing

        F 1 Reply Last reply
        0
        • C Chatura Dilan

          Or You can use a MaskedTestbox to do it Or Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If (AscW(e.KeyChar) < 48 Or AscW(e.KeyChar) > 57) Then e.KeyChar = Nothing End If End Sub

          Regards,

          Chatura Dilan

          If at first you don't succeed, try; try again, so that you know what not to do the next time. The answer is out there. -- modified at 23:25 Tuesday 4th April, 2006 'sorry.. when you use e.KeyChar = Chr(Keys.Back), other keys always do backspace's job. I corrected it. It must be e.KeyChar = Nothing

          F Offline
          F Offline
          FrankyT
          wrote on last edited by
          #4

          see...easy answers hey...slang is the vernacular for the vernacular...wow

          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