|
-
February 4th, 2010, 08:30 PM
#1
New to VB, need help with Try/Catch
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?
-
February 4th, 2010, 08:36 PM
#2
Re: New to VB, need help with Try/Catch
It is basically the same as c#.
Paste your C# code and we should be able to translate it for you.
-
February 5th, 2010, 02:52 AM
#3
Re: New to VB, need help with Try/Catch
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
-
February 5th, 2010, 06:30 AM
#4
Re: New to VB, need help with Try/Catch
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
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
February 7th, 2010, 05:56 PM
#5
Re: New to VB, need help with Try/Catch
Code:
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?
-
February 9th, 2010, 06:15 AM
#6
Re: New to VB, need help with Try/Catch
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...
Code:
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
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
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
|