I am building an application that accepts input entered into textboxes, then checks the input for negative values, etc. before writing it to a file. If the data does not meet the conditions, a message box pops up letting the user know. The problem I am having is that after it checks the data and displays the message box, it continues to save the input to the file anyway. How do I make it only write to the file if all the data meets my conditions? I apologize if this seems really basic, I am in my first year of a programming course!
-
Are you talking of data that is entered in a form bound to a dataset? – Olivier Jacot-Descombes Dec 11 '11 at 17:56
-
No, just data entered into textboxes. – Laura M Dec 11 '11 at 18:02
Well, you could do it like this:
'Checks here
If <data does not match>
MessageBox.Show("Your data is invalid!")
Exit Sub
End If
<code for writing to a file>
"Exit Sub" will exit the current subroutine (function) and not do the code you will place behind the if-block.
-
See here for the correct ways to exit a VB.Net app: geekswithblogs.net/mtreadwell/archive/2004/06/06/6123.aspx – Eight-Bit Guru Dec 11 '11 at 18:14