Results 1 to 8 of 8

Thread: [RESOLVED] Button cannot do job if...[HELP]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Resolved [RESOLVED] Button cannot do job if...[HELP]

    I want it so that when i click a button(button1) and there is no text in textbox1, the button does not work and a msgbox comes out saying "You need to enter a text". What will the code be? Thanks!
    Last edited by x DeaDLy; May 23rd, 2009 at 07:20 PM.

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

    Re: Button cannot do job if...[HELP]

    Quote Originally Posted by x DeaDLy View Post
    I want it so that when i click a button(button1) and there is no text in textbox1, the button does not work and a msgbox comes out saying "You need to enter a text". What will the code be? Thanks!
    vb.net Code:
    1. Private Sub btnButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnButton1.Click
    2.     If TextBox1.Text = "" Then
    3.         MessageBox.Show("You need to enter a text", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
    4.     End If
    5. End Sub
    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: Button cannot do job if...[HELP]

    Quote Originally Posted by JugglingReferee View Post
    vb.net Code:
    1. Private Sub btnButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnButton1.Click
    2.     If TextBox1.Text = "" Then
    3.         MessageBox.Show("You need to enter a text", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
    4.     End If
    5. End Sub
    Thank you so much! +rep

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: [RESOLVED] Button cannot do job if...[HELP]

    Ok what my button does is generate a random code, i implemented this code and it does show the error message box but, it still generates a code in "TEXTBOX2" How can i not make it generate a random code in textbox2 if there is no text in textbox1?

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

    Re: [RESOLVED] Button cannot do job if...[HELP]

    Also, note that you did say "the button does not work". You can disable the button so that it will not respond if a user tries to click it:

    vb.net Code:
    1. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    2.     If TextBox1.Text = "" Then
    3.         Button1.Enabled = False
    4.     Else If TextBox1.Text <> "" Then
    5.         Button1.Enabled = True
    6.     End If
    7. End Sub
    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

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    96

    Re: [RESOLVED] Button cannot do job if...[HELP]

    Quote Originally Posted by JugglingReferee View Post
    Also, note that you did say "the button does not work". You can disable the button so that it will not respond if a user tries to click it:

    vb.net Code:
    1. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    2.     If TextBox1.Text = "" Then
    3.         Button1.Enabled = False
    4.     Else If TextBox1.Text <> "" Then
    5.         Button1.Enabled = True
    6.     End If
    7. End Sub
    THX SO MUCH and i found the right code to make this work
    Code:
    If TextBox1.Text = "" Then
                MessageBox.Show("You need to enter a text", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
                TextBox2.Text = "NO TEXT ENTERED!"
            Else
                TextBox2.Text = generateRandomCombination()
            End If
    Thx for the help

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

    Re: [RESOLVED] Button cannot do job if...[HELP]

    Quote Originally Posted by x DeaDLy View Post
    Ok what my button does is generate a random code, i implemented this code and it does show the error message box but, it still generates a code in "TEXTBOX2" How can i not make it generate a random code in textbox2 if there is no text in textbox1?
    So you've already got code in Button1 that generates something for TextBox2.

    Change the code to this:

    vb.net Code:
    1. Private Sub btnButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnButton1.Click
    2.     If TextBox1.Text = "" Then
    3.         MessageBox.Show("You need to enter a text", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
    4.     Else If TextBox1.Text <> "" Then
    5.  
    6.         ' in this section, put the code that generates the code for TextBox2.
    7.  
    8.     End If
    9. End Sub



    If TextBox1.Text = "" Then

    MessageBox.Show("You need to enter a text", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)

    Else If TextBox1.Text <> "" Then

    ' in this section, put the code that generates the code for TextBox2.

    End If



    The red code will check to see if TextBox1 is blank. If it is blank, then the error Message Box is shown.

    The blue code will check to see if the TextBox1 is not blank. If it is not blank, then the code that fills TextBox2 is executed.
    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

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

    Re: [RESOLVED] Button cannot do job if...[HELP]

    Quote Originally Posted by x DeaDLy View Post
    THX SO MUCH and i found the right code to make this work
    Code:
    If TextBox1.Text = "" Then
                MessageBox.Show("You need to enter a text", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
                TextBox2.Text = "NO TEXT ENTERED!"
            Else
                TextBox2.Text = generateRandomCombination()
            End If
    Thx for the help

    Yup, that works too!
    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

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