Visual Basic Electric Billing program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jessie Pelenio
    New Member
    • Sep 2007
    • 1

    #1

    Visual Basic Electric Billing program

    Hello friends. I am Jessie from the Philippines. Friends my problem is how to restrict my textbox so that the users cannot encode a letter.
    Last edited by Jessie Pelenio; Sep 28 '07, 04:11 AM. Reason: correction
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by Jessie Pelenio
    Hello friends. I am Jessie from the Philippines. Friends my problem is how to restrict my textbox so that the users cannot encode a letter.
    This has been covered in a couple of recent posts here. But probably your simplest solution is to use a Masked Edit control, which allows you to control the format of the input.

    Otherwise, you can filter out the keys you don't want by intercepting them in the KeyDown event procedure.
    Last edited by Killer42; Oct 7 '07, 04:50 AM.

    Comment

    • jamesd0142
      Contributor
      • Sep 2007
      • 471

      #3
      Code may be slightly incorrect but the idea is here...

      on form keypress function,

      if e.keychar() <> "0" | "1" | "2".......| "9" then
      msgbox("please only use digits")
      end if

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        Write this code in KeyPress Event of textbox :

        [code=vb]
        Private Sub TextBox1_KeyPre ss(ByVal sender As Object, ByVal e As System.Windows. Forms.KeyPressE ventArgs) Handles TextBox1.KeyPre ss
        If IsNumeric(e.Key Char) Then
        e.Handled = False
        Else
        e.Handled = True
        End If
        End Sub
        [/code]


        REgards
        Veena

        Comment

        • Luzuko
          New Member
          • Sep 2007
          • 8

          #5
          Hi ,

          i just want to thank you for the piece of code i got from you.
          it's working perfectly on VB 2005 controls, however we're building our controls using Microsoft expression-Blend(user interface) and then program the user interface via Vb 2005. Now the problem is that the keypressed event doesn't show when we use the code on our User interface. Do you know any other event we can use for that code.

          Comment

          • QVeen72
            Recognized Expert Top Contributor
            • Oct 2006
            • 1445

            #6
            Hi,

            You can check in Changed Event of the textbox, it fires whenever you add/edit/delete anything in a textbox, maybe you may have to modify a bit.

            Regards
            Veena
            Last edited by Killer42; Oct 7 '07, 04:51 AM.

            Comment

            Working...