|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
use try catch to check a text boxHello,
I am using VB2005. I would like to check a textbox to see if it is blank using a Try Catch block. I assumed an easy way to do that would be to perform some action on the string that can't be done if the text box is blank, then catch it. But I can't find an action to perform that errors if the text box is blank. I don't want to use If Then Else. Can anyone help? Rip That sounds like overkill for just checking if the textbox is blank.
Throwing and catching exceptions is somewhat expensive, and not something that should be done unless there is an actual error occurring. A textbox being empty is not an unexpected error - it is something you can easily catch. Something like this should work: If String.IsNullOrEmpty(TextBox1.Text) Then ' textbox empty Else ' textbox not empty End If. Show quoteHide quote "RipperT @comcast.net>" <rippert<nospam> wrote in message news:u7$kHnj5GHA.1256@TK2MSFTNGP04.phx.gbl... > Hello, > > I am using VB2005. I would like to check a textbox to see if it is blank > using a Try Catch block. I assumed an easy way to do that would be to > perform some action on the string that can't be done if the text box is > blank, then catch it. But I can't find an action to perform that errors if > the text box is blank. I don't want to use If Then Else. Can anyone help? > > Rip > If textbox.Text.Trim.Length = 0 then Throw New Exception("foo")
Izzy RipperT wrote: Show quoteHide quote > Hello, > > I am using VB2005. I would like to check a textbox to see if it is blank > using a Try Catch block. I assumed an easy way to do that would be to > perform some action on the string that can't be done if the text box is > blank, then catch it. But I can't find an action to perform that errors if > the text box is blank. I don't want to use If Then Else. Can anyone help? > > Rip Something like :
chk.Checked=(txt.Text="") or similar depending on what you mean by "blank". Else elaborate a bit on the reason why you absolutely need a try/catch block (which sounds for now like a cumbersome way to do something simple). -- Patrice "RipperT @comcast.net>" <rippert<nospam> a écrit dans le message de news: u7$kHnj5GHA.1***@TK2MSFTNGP04.phx.gbl...Show quoteHide quote > Hello, > > I am using VB2005. I would like to check a textbox to see if it is blank > using a Try Catch block. I assumed an easy way to do that would be to > perform some action on the string that can't be done if the text box is > blank, then catch it. But I can't find an action to perform that errors if > the text box is blank. I don't want to use If Then Else. Can anyone help? > > Rip >
Q: closing forms
CURRENT INDEX of Iteration on ILIST collection ? 1.1 equivalent for Drawing.Icon.ExtractAssociatedIcon? Accessing the Class Name of a Shared Method Writing Custom DLLs in VB.net 2 Help with using bits in an integer Strings, a couple of questions like difference between += and &= new form copy and paste into webbrowser Set Statement vs Function |
|||||||||||||||||||||||