Question:
Visual Basic - How to restart my program so the User doesn't have to do it manually?
Rob Gane
2011-09-21 02:21:29 UTC
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
If txtUserLength.Text = "" And txtUserWidth.Text = "" Then
MsgBox("Please enter both Width and Length")
Call Clear()
ElseIf txtUserLength.Text = "" Then
MsgBox("Please enter a Length")
Call Clear()
ElseIf txtUserWidth.Text = "" Then
MsgBox("Please enter a Width")
Call Clear()
End If

Once a message box has been closed, the program continues and then there are problems (as the text box was empty) and the program stops. Obviously I have the If statements so that the user has to enter values into the text boxes. How can I make the program (or the code for the button) restart so that the user can have another chance to enter values without having to manually restart the program?

Thanks.
Five answers:
anonymous
2011-09-21 04:17:17 UTC
You don't need to restart your application, you can just add a Return statement if your conditions are not met. For example:



Call Clear()

Return



But to answer your question, in order to restart an application use:

Application.Restart()
anonymous
2016-09-27 19:02:02 UTC
dubious its on the whole utilized in developing macros in excel, employers are watching extra at languages like C# as it is constitution is strict, in different phrases each and every assertion need to result in a semicolon or the app wont run, while visible elementary you'll put out of your mind it and the app could nonetheless run. Also it is dependent what style of programming you are going into, for video games and OS's C++ and python are much more likely to aid you out. Java is first-class for internet and cellphone programs, as it's move gadget suitable that's so long as you'll get the runtime at the gadget the app will paintings. As such it is utilized in telephones, i-(pads, pods, telephones), and many others.
csicky
2011-09-21 03:10:16 UTC
To correct your problem :



check those values before using them, and if they're empty or not what you expect, re-prompt the user.



To answer your question:

Again: this is not the solution, it is the answer to your question!



Put your code from the btnCalc.Click in a try / catch (don't know the syntax in vb.net, only C#).

Then in the catch insert:



// This will launch a new instance of your application.

System.Diagnostics.Process.Start("name of your application.exe");

// This will close the current app

Application.Exit();
Neil
2015-08-17 23:08:28 UTC
Application.exit() works, as does Application.end()

Problem is it causes visual studio to lock .exe and /or .pdb files in the bin folder.

I have created a junk folder and drag offending files into the junk folder.

If Application.xx is not call, it does not seem to be a problem.

Application.exit... a problem.

Just plain end works
gennifer
2016-10-16 10:17:01 UTC
Application.restart


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...