![]() | | ||||||||
| | #1 |
| HyperActive Warrior War Room Member Join Date: Jan 2009
Posts: 152
Thanks: 1
Thanked 50 Times in 13 Posts
|
I have been fighting this problem for about 3 hours now and nothing I do seems to work. I am working on a small browser program that I am putting a small error handler type issue together. What I want to do is have a button become enabled when there is text in a text box on the screen and disabled when there is no text in the box. The result will be when a url is in the text box the button is clickable and the web browser takes the url and if there is no url in the text box nothing will happen sice they can't click the button. This is the code I have been trying to play with. If UrlTextBox.Text = Text Then Button4.Enabled = True else button4.enabled = false but when I run the program the button is still enabled. I have even tried simular lines of code and putting the code in different declerations but nothing seems to work. This isn't difficult or at least I don't think it is. Can anyone give me any advice. Thanks |
| | |
| | #2 |
| Web Developer, IT Support War Room Member Join Date: Dec 2008 Location: Birmingham, UK
Posts: 513
Thanks: 10
Thanked 77 Times in 65 Posts
|
Firstly, you'll need the code to be within the textbox's onChange function (or VB similar function - I can't remember from memory). Then, you'd need to use something along the lines of: If UrlTextBox.Text = "" Then Button4.Enabled = False Else Button4.Enabled = True |
| | |
| | |
| | #3 |
| HyperActive Warrior War Room Member Join Date: Jan 2009
Posts: 152
Thanks: 1
Thanked 50 Times in 13 Posts
|
thank youI did that before but may have put in the wrong place.
|
| | |
| | #4 |
| Warrior Member Join Date: Nov 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
hi.Niche, you could use the code earlier suggested or better still make use of the keypress event of your textbox.You can place this code in the keypress or change events: If Text1.Text <> "" Then Command1.Enabled = True Else Command1.Enabled = False Exit Sub End If YMO |
| | |
| | #5 |
| Banned War Room Member Join Date: Oct 2009
Posts: 183
Thanks: 4
Thanked 21 Times in 19 Posts
| Code: 'This checks if the length of a string without leading/trailing spaces is greater than 0
If Len(Trim$(Text1.Text)) > 0 Then
'You might want to check for valid entries here, but this line below enables it
Command1.Enabled = True
Else
Command1.Enabled = False
End If
End Sub -Malik |
| | |
| | #6 |
| HyperActive Warrior War Room Member Join Date: Sep 2009 Location: Canada
Posts: 137
Thanks: 4
Thanked 35 Times in 18 Posts
|
try this: Code: Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If (TextBox1.Length <= 0) then
Button1.Enabled = False
else
Button1.Endabled = True
End If
End Sub |
| VisualWebEffects- Web Application Development, PC Software Development and Identity Design services
| |
| | |
| | #7 | |
| Steve Hawkins War Room Member Join Date: Apr 2009 Location: Whitleybay, uk
Posts: 1,967
Blog Entries: 2 Thanks: 11
Thanked 923 Times in 185 Posts
| Quote:
| |
| | ||
| | |
| | #8 |
| Warrior Member Join Date: Oct 2009
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
Insert this into the TextChanged part of Textbox: If Len(Textbox1.Text) = 0 Then Command1.Enabled = False Else Command1.Enabled = True End If If your Textbox is empty default on startup then just set Enabled = False on the command button. Edit: Next time ask for help sooner, 3 hours is a long time.. =) |
| | |
![]() |
|
| Tags |
| butt, kicking, problem, simple |
| Thread Tools | |
| |
![]() |