-
Feb 25th, 2015, 07:22 AM
#1
Thread Starter
New Member
Textbox value
Hello Guys, I'm pretty new to the programming business and just do it in my free time.
To the point:
I want to read out of a textbox if it's value is zero or is empty. If its empty or it's value zero then button1 should disappear and the
Key.Enter shouldn't be allowed anymore in this Textbox.
I don't care how its programmed, it should just work.
thats my actual code, but doesn't work
Code:
If (Not String.IsNullOrEmpty(TextBox1.Text)) Then
Button1.Visible = False
End If
If (not string.IsNullOrWhiteSpace(TextBox1.Text)) Then
Button1.Visible = False
End If
End Sub
-
Feb 25th, 2015, 09:57 AM
#2
Re: Textbox value
How is it that this code is executing right now? That is, how is it being called?
I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Feb 25th, 2015, 10:29 AM
#3
New Member
Re: Textbox value
Originally Posted by enii
Hello Guys, I'm pretty new to the programming business and just do it in my free time.
To the point:
I want to read out of a textbox if it's value is zero or is empty. If its empty or it's value zero then button1 should disappear and the
Key.Enter shouldn't be allowed anymore in this Textbox.
I don't care how its programmed, it should just work.
thats my actual code, but doesn't work
Code:
If (Not String.IsNullOrEmpty(TextBox1.Text)) Then
Button1.Visible = False
End If
If (not string.IsNullOrWhiteSpace(TextBox1.Text)) Then
Button1.Visible = False
End If
End Sub
there to way to do that
1:
If TextBox5.Text = "" or TextBox5 = " " Then
Button1.Visible = true
else
Button1.Visible = False
end if
2:
If Not TextBox5.Text = "" Then
' your code here
Button1.Visible = False
Else
MsgBox("The text box is emty")
End If
-
Feb 25th, 2015, 10:46 AM
#4
Re: Textbox value
Originally Posted by enii
Hello Guys, I'm pretty new to the programming business and just do it in my free time.
To the point:
I want to read out of a textbox if it's value is zero or is empty. If its empty or it's value zero then button1 should disappear and the
Key.Enter shouldn't be allowed anymore in this Textbox.
I don't care how its programmed, it should just work.
thats my actual code, but doesn't work
Code:
If (Not String.IsNullOrEmpty(TextBox1.Text)) Then
Button1.Visible = False
End If
If (not string.IsNullOrWhiteSpace(TextBox1.Text)) Then
Button1.Visible = False
End If
End Sub
Saying it doesn't work is like walking into the doctor's office and saying "it hurts" and expecting him to know what you're talking about... no one does that (as far as I know)...
We're not psychic, we can't read your mind. We're also not sitting in your lap, so we don't see what you're seeing.
Do you get an error? Does something happen that shouldn't? Is there something that should happen that isn't? Did your fingers fly off? Can happen, I've seen it on TV. More than once too! I'd dare say that your fingers flying off is an exception...
Have you set a breakpoint and stepped through the code to see why it isn't working? Could be the logic... could be that something isn't the value you assume it to be. Where is this code? Is it in an event, a sub - is the sub even being called?
-tg
-
Feb 25th, 2015, 10:57 AM
#5
Re: Textbox value
And before you ask. BreakPoint Video
Burn the land and boil the sea
You can't take the sky from me
~T
-
Feb 25th, 2015, 02:39 PM
#6
Hyperactive Member
Re: Textbox value
Originally Posted by enii
If its empty or it's value zero then button1 should disappear
Code:
If (Not String.IsNullOrEmpty(TextBox1.Text)) Then
Button1.Visible = False
End If
If (not string.IsNullOrWhiteSpace(TextBox1.Text)) Then
Button1.Visible = False
End If
End Sub
You say you want the button to disappear if the TextBox is empty, but your code does the exact opposite. The Function IsNullOrEmpty returns true if the String parameter is null or empty. So "If String.IsNullOrEmpty(TextBox1.Text) Then Button1.Visible = False" will do what you want; remove the Not at the beginning of your condition. You could also shorten it to "Button1.Visible = Not (String.IsNullOrEmpty(TextBox1.Text))" and get rid of the If-statement. BTW, IsNullOrEmpty is essentially the same as IsNullOrWhiteSpace except that the latter function also considers Strings of nothing but whitespace as being "empty" as well. So you'd only really need to use the one function (probably the IsNullOrWhiteSpace).
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
|