MsgBox displays sometimes and sometimes not?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
roysubs
Posts: 428
Joined: 29 Sep 2018, 16:37

MsgBox displays sometimes and sometimes not?

Post by roysubs » 30 Sep 2018, 09:37

I have a couple of questions with the below code.
1. When I first run this, the MsgBox displays perfectly.
2. When I do a Ctrl+Win+r to reload the script, the MsgBox for the "Do you really..." appears, but the MsgBox on the first line does *not* display.
I can't understand this behaviour. When I reload the script, shouldn't the MsgBox in line 1 display?

Code: Select all

Msgbox, %A_ComputerName% %A_OSVersion% %A_ScriptFullPath%

^#r::   ; Ctrl+Win+r to reload this script
    MsgBox, Do you really want to reload this script?
    ifMsgBox, Yes
        Reload ; function to restart the current script
	return
return

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: MsgBox displays sometimes and sometimes not?

Post by swagfag » 30 Sep 2018, 09:44

Reload is unreachable code in ur example. Ure checking to see if the msgbox button u clicked is a "Yes" button, but the msgbox didnt have a "Yes" button in the first place.
change ur condition, or change your msgbox type

roysubs
Posts: 428
Joined: 29 Sep 2018, 16:37

Re: MsgBox displays sometimes and sometimes not?

Post by roysubs » 30 Sep 2018, 09:58

The active MsgBox line (after the ^#r keypress is : MsgBox, Do you really want to reload this script?
I've put "Yes" there, so I see what you mean and that cannot work.

So, I've now changed that line to "ifMsgBox, OK" (since the MsgBox displays an "OK" box), but it still does not work.
Any ideas how I get it to do the reload?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: MsgBox displays sometimes and sometimes not?

Post by swagfag » 30 Sep 2018, 10:03

roysubs wrote:So, I've now changed that line to "ifMsgBox, OK" (since the MsgBox displays an "OK" box), but it still does not work.
yes, it does:

Code: Select all

Msgbox, %A_ComputerName% %A_OSVersion% %A_ScriptFullPath%

^#r::   ; Ctrl+Win+r to reload this script
    MsgBox, Do you really want to reload this script?
    ifMsgBox, OK
        Reload ; function to restart the current script
	return
return

garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: MsgBox displays sometimes and sometimes not?

Post by garry » 30 Sep 2018, 10:40

[ double post deleted ]
Last edited by garry on 30 Sep 2018, 10:48, edited 1 time in total.

garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: MsgBox displays sometimes and sometimes not?

Post by garry » 30 Sep 2018, 10:47

msgbox has different options , depending use OK or YES etc ...
and show msgbox alwaysontop so it can't be hidden behind another window ...
see msgboxcreator script from users
https://autohotkey.com/boards/viewtopic.php?t=30173 ;- boiler
Thalon uploaded
https://autohotkey.com/boards/viewtopic.php?t=6928

Code: Select all

;- msgbox alwaysontop 
#singleinstance,force
msgbox, 262208,Info ,Computername=%A_ComputerName%`nOSVersion        =%A_OSVersion%`nAhkVersion      =%A_ahkversion%,4          ;- show for 4 seconds
return
^#r::   ; Ctrl+Win+r to reload this script
msgbox, 262436,RELOAD(?) ,Do you really want to reload this script?
ifMsgBox, Yes
   Reload                ;- function to restart the current script
return

roysubs
Posts: 428
Joined: 29 Sep 2018, 16:37

Re: MsgBox displays sometimes and sometimes not?

Post by roysubs » 01 Oct 2018, 04:34

Excellent, thanks for these answers, and the additional
I guess it was not working as I was putting it inside another script, and I had additional return statements, maybe that was breaking it.

Just on this syntax in AHK, is it correct that it's sort of python like things after a declaration like ^#r:: don't need an explicit 'return' after multiple lines, and it just starts on a new hotkey declaration when it sees a new '::' or something? Finding it hard to know when to put down 'return' statements and not (I take it that the return below is for the ifMsgBox, and not for the ^#r:: ?).

Code: Select all

^#r::
    ifMsgBox, OK
        Reload
    return

^#s::
    <do something else>
But then I've seen other scripts that use #if and they don't have a return at all. I've tried looking in the documentation, but still not clear on how and when to use 'return' ?

Code: Select all

; The #IfWin directive creates context-sensitive hotkeys. Such hotkeys perform a different action depending on the
; type of window that is active or exists. https://autohotkey.com/docs/commands/_IfWinActive.htm
#IfWinActive ahk_class CabinetWClass
^f::
    Run %explorerpath%
#IfWinActive  ; turn off context sensitivity

roysubs
Posts: 428
Joined: 29 Sep 2018, 16:37

Re: MsgBox displays sometimes and sometimes not?

Post by roysubs » 01 Oct 2018, 04:34

<duplicate post deleted>
Last edited by roysubs on 01 Oct 2018, 04:35, edited 2 times in total.

Post Reply

Return to “Ask for Help (v1)”