Page 1 of 1

End Script

Posted: 16 May 2022, 10:58
by Ben the Coder
I have a script that I am trying to stop, but ExitApp and Return aren't working for me. It still keeps running in the background, doing nothing. Can anyone help me with this?
Thanks!

Re: End Script

Posted: 16 May 2022, 11:00
by boiler
ExitApp would always work, so the fact that it's not exiting means that your script isn't actually executing that line. You would have to show the details of your script so we can identify the issues with how it's structured and how the code flows.

Re: End Script

Posted: 16 May 2022, 15:41
by Ben the Coder
Wait...
I've figured out a solution! My script is working now!

Re: End Script

Posted: 16 May 2022, 15:50
by BoBo
@Ben G - would you mind showing it?! ;)

Re: End Script

Posted: 16 May 2022, 15:54
by Ben the Coder
Sorry, do you want me to show my script?

Re: End Script

Posted: 16 May 2022, 15:59
by BoBo
Yep, especially how you've solved your issue.

Re: End Script

Posted: 16 May 2022, 16:11
by Ben the Coder
The problem (for me) was that the script was running in the background, so when you went to re-open it sometime, it would put up a pop-up saying that there was a older version of this script running, and asking if I want to terminate the older one and run the new one. I "solved" this by adding the code:

Code: Select all

#SingleInstance Force
Here's my entire program below:

Code: Select all

#SingleInstance Force
MsgBox, Welcome to SimpleCalc!
InputBox, Firstnum, SimpleCalc, Enter first number.
InputBox, Secnum, SimpleCalc, Enter second number.

 ;Operator buttons below
Gui, -Caption +LastFound -SysMenu +ToolWindow -DPIScale
Gui, Font, s15
Gui, Add, Text,, Please enter operator:   
Loop, Parse,% "+,-,*,/,^", CSV
	Gui, Add, Button, x+ y20 gOperator,% A_LoopField
Gui, Show
Return
Operator:
Operator := StrReplace(A_GuiControl, "&&", "&")
Gui, Destroy
Switch, Operator
{
Case "+":Result := Firstnum + Secnum
; ...
Case "*":Result := Firstnum * Secnum
; ...
Case "-":Result := Firstnum - Secnum
; ...
Case "/":Result := Firstnum / Secnum
; ...
Case "^":Result := Firstnum ** Secnum
}
MsgBox,% "The answer is: " Result
MsgBox, 4,, Would you like to start another session?
IfMsgBox Yes
	Run, SimpleCalc.exe
else
    Sleep, 10000
    return
return
return
ExitApp [, ExitCode]
Thanks so much everyone!

Re: End Script

Posted: 16 May 2022, 16:35
by BoBo
Congrats to you for solving this on your own! :thumbup: