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?
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.
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
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
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?
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