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. Other Discussions
  3. The Weird and The Wonderful
  4. Check input for Alfanumeric...

Check input for Alfanumeric...

Scheduled Pinned Locked Moved The Weird and The Wonderful
database
7 Posts 6 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.
  • D Offline
    D Offline
    ddecoy
    wrote on last edited by
    #1

    Private Sub textBox1_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles textBox1.KeyPress
    Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
    Dim Index As Short = textBox1.GetIndex(eventSender)
    If InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" & Chr(8), Chr(KeyAscii)) > 0 Or KeyAscii < 32 Then
    Else
    KeyAscii = 0
    Beep()
    End If
    eventArgs.KeyChar = Chr(KeyAscii)
    If KeyAscii = 0 Then
    eventArgs.Handled = True
    End If
    End Sub

    Getting sick of these kind of codeblocks ... oh yeah, remember Char(8) is a backspace :laugh: If anyone knows why he might have written this line :

    Dim Index As Short = textBox1.GetIndex(eventSender)

    I have no clue ...

    N S D 3 Replies Last reply
    0
    • D ddecoy

      Private Sub textBox1_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles textBox1.KeyPress
      Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
      Dim Index As Short = textBox1.GetIndex(eventSender)
      If InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" & Chr(8), Chr(KeyAscii)) > 0 Or KeyAscii < 32 Then
      Else
      KeyAscii = 0
      Beep()
      End If
      eventArgs.KeyChar = Chr(KeyAscii)
      If KeyAscii = 0 Then
      eventArgs.Handled = True
      End If
      End Sub

      Getting sick of these kind of codeblocks ... oh yeah, remember Char(8) is a backspace :laugh: If anyone knows why he might have written this line :

      Dim Index As Short = textBox1.GetIndex(eventSender)

      I have no clue ...

      N Offline
      N Offline
      NickPace
      wrote on last edited by
      #2

      ddecoy wrote:

      I have no clue ...

      Welcome to my world... ;)

      -NP Never underestimate the creativity of the end-user.

      J 1 Reply Last reply
      0
      • N NickPace

        ddecoy wrote:

        I have no clue ...

        Welcome to my world... ;)

        -NP Never underestimate the creativity of the end-user.

        J Offline
        J Offline
        Jason Vetter
        wrote on last edited by
        #3

        The best line in this function is Beep()!

        OriginalGriffO 1 Reply Last reply
        0
        • J Jason Vetter

          The best line in this function is Beep()!

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          We aren't in the Lounge now - no need to censor your language... ;)

          Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • D ddecoy

            Private Sub textBox1_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles textBox1.KeyPress
            Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
            Dim Index As Short = textBox1.GetIndex(eventSender)
            If InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" & Chr(8), Chr(KeyAscii)) > 0 Or KeyAscii < 32 Then
            Else
            KeyAscii = 0
            Beep()
            End If
            eventArgs.KeyChar = Chr(KeyAscii)
            If KeyAscii = 0 Then
            eventArgs.Handled = True
            End If
            End Sub

            Getting sick of these kind of codeblocks ... oh yeah, remember Char(8) is a backspace :laugh: If anyone knows why he might have written this line :

            Dim Index As Short = textBox1.GetIndex(eventSender)

            I have no clue ...

            S Offline
            S Offline
            supercat9
            wrote on last edited by
            #5

            The code isn't testing for alphanumeric--just alphabetic. That having been said, I don't see anything overly hideous. I would expect VB to recognize the string with the letters and backspace as a constant, so the code simply searches for an input character in a constant string. Not gorgeous (using a named constant called AllowableKeys or something would help), but the list of allowable characters can be easily adjusted by changing the string. If upper and lower case are going to be handled identically elsewhere, it might have been nice to convert to uppercase and just check against uppercase letters. As for my own style, if I were just checking against one contiguous range of characters, I'd use the >= and <= to check the range. With two ranges, or one range plus one or two other characters, I'd still probably use those. With more than that, I'd likely just search in a string with all valid characters.

            D 1 Reply Last reply
            0
            • S supercat9

              The code isn't testing for alphanumeric--just alphabetic. That having been said, I don't see anything overly hideous. I would expect VB to recognize the string with the letters and backspace as a constant, so the code simply searches for an input character in a constant string. Not gorgeous (using a named constant called AllowableKeys or something would help), but the list of allowable characters can be easily adjusted by changing the string. If upper and lower case are going to be handled identically elsewhere, it might have been nice to convert to uppercase and just check against uppercase letters. As for my own style, if I were just checking against one contiguous range of characters, I'd use the >= and <= to check the range. With two ranges, or one range plus one or two other characters, I'd still probably use those. With more than that, I'd likely just search in a string with all valid characters.

              D Offline
              D Offline
              ddecoy
              wrote on last edited by
              #6

              supercat9 wrote:

              The code isn't testing for alphanumeric--just alphabetic

              Yes, Alfabetic I meant, and don't forget the backspace :)

              1 Reply Last reply
              0
              • D ddecoy

                Private Sub textBox1_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles textBox1.KeyPress
                Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
                Dim Index As Short = textBox1.GetIndex(eventSender)
                If InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" & Chr(8), Chr(KeyAscii)) > 0 Or KeyAscii < 32 Then
                Else
                KeyAscii = 0
                Beep()
                End If
                eventArgs.KeyChar = Chr(KeyAscii)
                If KeyAscii = 0 Then
                eventArgs.Handled = True
                End If
                End Sub

                Getting sick of these kind of codeblocks ... oh yeah, remember Char(8) is a backspace :laugh: If anyone knows why he might have written this line :

                Dim Index As Short = textBox1.GetIndex(eventSender)

                I have no clue ...

                D Offline
                D Offline
                Dr Walt Fair PE
                wrote on last edited by
                #7

                This looks like it was converted from an old dialect of Basic. The only thing I see as "odd" is the & Chr(8), since the check for < 32 would catch all the common Ctl chars, including Bksp, anyway. But my guess is that it was converted and modified a couple of time to end up with that. The Dim Index As Short = textBox1.GetIndex(eventSender) line looks like something left over from a previous mod or from some debugging effort. It doesn't look like Index is used at all.

                CQ de W5ALT

                Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

                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