Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 11-04-2009, 01:58 PM   #1
HyperActive Warrior
War Room Member
 
NicheExposed's Avatar
 
Join Date: Jan 2009
Posts: 152
Thanks: 1
Thanked 50 Times in 13 Posts
Default simple vb problem kicking my butt...

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
NicheExposed is offline   Reply With Quote
Old 11-04-2009, 02:09 PM   #2
Web Developer, IT Support
War Room Member
 
n7 Studios's Avatar
 
Join Date: Dec 2008
Location: Birmingham, UK
Posts: 513
Thanks: 10
Thanked 77 Times in 65 Posts
Social Networking View Member's FaceBook Profile  View Member's Twitter Profile 
Default Re: simple vb problem kicking my butt...

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

n7 Studios is online now   Reply With Quote
Old 11-04-2009, 03:23 PM   #3
HyperActive Warrior
War Room Member
 
NicheExposed's Avatar
 
Join Date: Jan 2009
Posts: 152
Thanks: 1
Thanked 50 Times in 13 Posts
Default Re: simple vb problem kicking my butt...

thank youI did that before but may have put in the wrong place.
NicheExposed is offline   Reply With Quote
Old 11-05-2009, 06:17 AM   #4
YMO
Warrior Member
 
Join Date: Nov 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: simple vb problem kicking my butt...

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
YMO is offline   Reply With Quote
Old 11-05-2009, 06:44 AM   #5
Banned
War Room Member
 
Join Date: Oct 2009
Posts: 183
Thanks: 4
Thanked 21 Times in 19 Posts
Default Re: simple vb problem kicking my butt...

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
maybe that help.

-Malik
sanjid112 is offline   Reply With Quote
Old 11-05-2009, 09:52 AM   #6
HyperActive Warrior
War Room Member
 
VisualWebEffects's Avatar
 
Join Date: Sep 2009
Location: Canada
Posts: 137
Thanks: 4
Thanked 35 Times in 18 Posts
Contact Info
Send a message via Skype™ to VisualWebEffects
Default Re: simple vb problem kicking my butt...

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
Basically the Code that sanjid112 posted but instead of using the len function use the length function built into the textbox and wrap it in the TextChanged function. Doing this the TextChanged function should automatically be called when the user starts to type text. All you would need to do is change the compair number to whatever you need it to be. And ofc change the TextBox1 to whatever your textbox is named.

VisualWebEffects- Web Application Development, PC Software Development and Identity Design services
VisualWebEffects is offline   Reply With Quote
Old 11-05-2009, 04:27 PM   #7
Steve Hawkins
War Room Member
 
TrafficMystic's Avatar
 
Join Date: Apr 2009
Location: Whitleybay, uk
Posts: 1,967
Blog Entries: 2
Thanks: 11
Thanked 923 Times in 185 Posts
Social Networking View Member's Twitter Profile  View Member's YouTube Profile
Default Re: simple vb problem kicking my butt...

Quote:
Originally Posted by VisualWebEffects View Post
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
Basically the Code that sanjid112 posted but instead of using the len function use the length function built into the textbox and wrap it in the TextChanged function. Doing this the TextChanged function should automatically be called when the user starts to type text. All you would need to do is change the compair number to whatever you need it to be. And ofc change the TextBox1 to whatever your textbox is named.
Also add some code on the show or load event to check the values on startup of the form.

TrafficMystic is offline   Reply With Quote
Old 11-05-2009, 05:19 PM   #8
Warrior Member
 
Join Date: Oct 2009
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: simple vb problem kicking my butt...

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.. =)
warmlikecoffee is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Tags
butt, kicking, problem, simple

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 10:35 AM.