Results 1 to 4 of 4

Thread: [ask] textbot_changed

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2008
    Posts
    146

    [ask] textbot_changed

    i have a code
    Code:
    Private Sub txt1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt1.TextChanged
            Dim a As Integer
            txt1.SelectionStart = txt1.Text.Length
            a = txt1.SelectionStart
            If status = True And (Chr(Asc(txt1.SelectedText(a))) < Chr(48) Or Chr(Asc(txt1.SelectedText(a))) > Chr(57)) And Chr(Asc(txt1.SelectedText(a))) <> Chr(8) Then
                MsgBox("Only numeric text", MsgBoxStyle.OkOnly)
                txt1.Text = Chr(0)
                txt1.Focus()
            End If
        End Sub
    i want to make a checking everytime i input a character
    it's checking is it a numeric or not

    plz help me

    thx

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [ask] textbot_changed

    The TextChanged event does fire each time a change is made in the textbox like a single character keypress.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [ask] textbot_changed

    You should be using the KeyPress event for this. You can test the character before it is added to the control instead of after. There are NUMEROUS examples on the forum of limiting input in TextBoxes using this technique so I'd suggest a search.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: [ask] textbot_changed

    Just use this:

    Code:
    Private Sub txt1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txt1.KeyPress
        'Editing
    End Sub
    Last edited by MaximilianMayrhofer; Jul 9th, 2008 at 12:25 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width