José Perez
asked on
VB.Net How to Exit Sub - Exit Form???
Hi,
I have a form that runs a function that prints an invoice.
The user adds several data to the form, then he clicks the 'Print' button and the button runs a function ("Private Sub") that actually sends the information to the thermal printer... finally, after the printer do its job, it returns the control to the form clearing all values.
The issue is that, when the information is not complete, the function should exit and not continue the execution of the form because it clears all values when the only thing I need is to change/fix 1 value in the form.
So "Exit Sub" does not work because it continues the execution on the form, clearin all values :(
Is there any other way, or walkaround that allow me to exit the Sub or Function without continueing the execution?
Ref: https://msdn.microsoft.com/en-us/library/t2at9t47.aspx
I have a form that runs a function that prints an invoice.
The user adds several data to the form, then he clicks the 'Print' button and the button runs a function ("Private Sub") that actually sends the information to the thermal printer... finally, after the printer do its job, it returns the control to the form clearing all values.
The issue is that, when the information is not complete, the function should exit and not continue the execution of the form because it clears all values when the only thing I need is to change/fix 1 value in the form.
So "Exit Sub" does not work because it continues the execution on the form, clearin all values :(
Is there any other way, or walkaround that allow me to exit the Sub or Function without continueing the execution?
Ref: https://msdn.microsoft.com/en-us/library/t2at9t47.aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You should validate the data being sent to the Private Sub before it actually processes anything.
I would clear the values of the data on the form at the end of the sub that does the printing.
That way you could test each value with something like
If Textbox1.Text = "" then
Messagebox.Show("Please complete the form....")
Exit Sub
End If
If all data is present, do the print job then clear the values, then exit
That way you could test each value with something like
If Textbox1.Text = "" then
Messagebox.Show("Please complete the form....")
Exit Sub
End If
If all data is present, do the print job then clear the values, then exit
Just 1 more option to Mike's suggestion: you can place clearing code to separate sub/function and call it at the end of printing Sub (after all 'Exit Sub' calls)
ASKER
Not the answer I was expecting but it is a true answer :(