|
-
May 23rd, 2009, 07:13 PM
#1
Thread Starter
Lively Member
[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.
-
May 23rd, 2009, 07:36 PM
#2
Addicted Member
Re: Button cannot do job if...[HELP]
 Originally Posted by x DeaDLy
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:
Private Sub btnButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnButton1.Click
If TextBox1.Text = "" Then
MessageBox.Show("You need to enter a text", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
End If
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
-
May 23rd, 2009, 07:38 PM
#3
Thread Starter
Lively Member
Re: Button cannot do job if...[HELP]
 Originally Posted by JugglingReferee
vb.net Code:
Private Sub btnButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnButton1.Click
If TextBox1.Text = "" Then
MessageBox.Show("You need to enter a text", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
End If
End Sub
Thank you so much! +rep
-
May 23rd, 2009, 07:40 PM
#4
Thread Starter
Lively Member
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?
-
May 23rd, 2009, 07:44 PM
#5
Addicted Member
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:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text = "" Then
Button1.Enabled = False
Else If TextBox1.Text <> "" Then
Button1.Enabled = True
End If
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
-
May 23rd, 2009, 07:46 PM
#6
Thread Starter
Lively Member
Re: [RESOLVED] Button cannot do job if...[HELP]
 Originally Posted by JugglingReferee
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:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text = "" Then
Button1.Enabled = False
Else If TextBox1.Text <> "" Then
Button1.Enabled = True
End If
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
-
May 23rd, 2009, 07:49 PM
#7
Addicted Member
Re: [RESOLVED] Button cannot do job if...[HELP]
 Originally Posted by x DeaDLy
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:
Private Sub btnButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnButton1.Click 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 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
-
May 23rd, 2009, 07:51 PM
#8
Addicted Member
Re: [RESOLVED] Button cannot do job if...[HELP]
 Originally Posted by x DeaDLy
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|