Click to See Complete Forum and Search --> : New to VB, need help with Try/Catch
Xxsomethingxx
February 4th, 2010, 07:30 PM
Hi there,
I'm familiar with Visual C# and the try/catch for that but I cannot seem to figure out how to do the same thing in VB.
Basically I can't figure out how to get the try/catch to work with text boxes and input from the user and whatnot.
I've tried setting the textbox.text property = "" but that has no use, I've been trying to find something on google about it but I cannot seem to find a single thing about textbox try/catch statements. Is it possible to do it with text boxes?
sotoasty
February 4th, 2010, 07:36 PM
It is basically the same as c#.
Paste your C# code and we should be able to translate it for you.
HanneSThEGreaT
February 5th, 2010, 01:52 AM
Have a look at this FAQ :
http://www.codeguru.com/forum/showthread.php?t=383057
The FAQ's are still growing, unfortunately too slow for my liking, but still. Here are also some VB.NET FAQ's :
http://www.codeguru.com/forum/forumdisplay.php?f=76
Cimperiali
February 5th, 2010, 05:30 AM
Having seen you posted question in Vb 6.0 forum, let me clarify this:
Try..Catch...Finally...End Try is in Visual Basic Dot Net
You will not find it in Vb 6.0, where you have to use
On Error statement
Xxsomethingxx
February 7th, 2010, 04:56 PM
Try
txtBoxAmount.Text = String.Empty
Catch ex As Exception
Beep()
MessageBox.Show("Error: ")
End Try
I can't seem to find out how to make it throw the error when I push a button with a blank text box field. It shows no errors but the message box will not pop up, what am I doing wrong?
Cimperiali
February 9th, 2010, 05:15 AM
you stated in your code that textbox should be assigned an empty
string, which is perfectly legal and throw no error at all.
If you want to throw exception when it happens, use If
to test, and then throw your exception...
hile debugging, debugger will intercept the exception alting
execution of code, you will have to make it run clicking on green arrow...
Try
if String.IsNullOrEmpty(txtBoxAmount.Text.Trim) then
throw new exception ("The text cannot be empty!")
end if
Catch ex As Exception
Beep()
MessageBox.Show("Error: " & ex.message())
End Try
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.