Results 1 to 5 of 5

Thread: [RESOLVED] How to set Minimum character[HELP]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Resolved [RESOLVED] How to set Minimum character[HELP]

    How would i set a minimum number of characters in textbox1 for a button to work. and if the person does not enter the minimum number of characters, a messagebox pops up sayin something like "need at least 5 characters!" Thanks

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: How to set Minimum character[HELP]

    Set the button initially to disabled and try this:

    vb.net Code:
    1. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    2.         Me.Button1.Enabled = (Me.TextBox1.Text.Length > 5)
    3.     End Sub

    A MessageBox coming up would be really annoying I think from a UI point of view. That said, you could make it so when they click the button it checks the textbox length and then shows the MessageBox.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: How to set Minimum character[HELP]

    Thx so much it worked !!! +rep

  4. #4
    Addicted Member
    Join Date
    Apr 2009
    Location
    Near Dog River (sorta)
    Posts
    160

    Re: How to set Minimum character[HELP]

    Quote Originally Posted by x DeaDLy View Post
    How would i set a minimum number of characters in textbox1 for a button to work. and if the person does not enter the minimum number of characters, a messagebox pops up sayin something like "need at least 5 characters!" Thanks

    Quote Originally Posted by ForumAccount View Post
    Set the button initially to disabled and try this:

    vb.net Code:
    1. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    2.         Me.Button1.Enabled = (Me.TextBox1.Text.Length > 5)
    3.     End Sub

    A MessageBox coming up would be really annoying I think from a UI point of view. That said, you could make it so when they click the button it checks the textbox length and then shows the MessageBox.

    I agree with ForumAccount. The app that I'm currently working on has many of these cases where controls switch from Enabled to Disabled. I think it looks smart.
    PC #1: Athlon64 X2+Vista64+VS2008EE+.NET3.5 #2: XP (all flavours Ghost'd)+VS2008EE+.NET3.5
    Help Files: HelpMaker · Dr. Explain · Create Icons: IcoFX


    "Whoever eats my flesh and drinks my blood has eternal life, and I will raise him on the last day." John 6:54

  5. #5
    Hyperactive Member
    Join Date
    Apr 2009
    Posts
    358

    Re: How to set Minimum character[HELP]

    Quote Originally Posted by x DeaDLy View Post
    Thx so much it worked !!! +rep
    Or
    Code:
    if len(textbox1.text) < 5 Then
    Button1.Enabled=false
    Else
    Button1.Enabled=True
    End If

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