simple script only works the first time I use it Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jomaweb
Posts: 11
Joined: 20 Dec 2020, 06:01

simple script only works the first time I use it

18 Jan 2021, 11:08

My script is simple, reads a file and greps for mathing words. Escape key to close GUI.
The issue is it only works once. After first use the window icon appears on windows bar but is not visible.
I have to reload script to make GUI viisble again.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Gui, 1: New,, If WinExist("Search in C:\Users\joe\AutoHotkey\hotkeys.txt")
Gui, Add, Text,, Enter the command to search
Gui, Add, Edit, w600 vQuery gShowResult
Gui, Font, s14, Verdana
Gui, Add, Edit, wp h400
FileRead, contents, C:\Users\joe\AutoHotkey\hotkeys.txt
Return

^l:: Gui, Show

ShowResult:
   GuiControlGet, Query
   p := ""
   for k, v in StrSplit(Query, " ")
      (v != "" && p .= "\V*\Q" . v . "\E")
   p .= "\V*\R?"
   text := Query = "" ? "" : RegExReplace(contents, "si).*?(" . p . ")|.*", "$1")
   GuiControl,, Edit2, % text
   Return


GuiEscape:
{
	;MsgBox escape pressed
	Gui, 1:Destroy
	return
}
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: simple script only works the first time I use it

18 Jan 2021, 11:22

Code: Select all

.
.
.
FileRead, contents, C:\Users\joe\AutoHotkey\hotkeys.txt
Gui, Show
Return
:?:
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: simple script only works the first time I use it

18 Jan 2021, 11:25

boiler wrote:
18 Jan 2021, 11:18
Use Cancel instead of Destroy.
Shouldn't he 'hide' it instead? :think:
gregster
Posts: 9034
Joined: 30 Sep 2013, 06:48

Re: simple script only works the first time I use it

18 Jan 2021, 11:26

BoBo wrote:
18 Jan 2021, 11:25
boiler wrote:
18 Jan 2021, 11:18
Use Cancel instead of Destroy.
Shouldn't he 'hide' it instead? :think:
It's the same: https://www.autohotkey.com/docs/commands/Gui.htm#Cancel
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: simple script only works the first time I use it

18 Jan 2021, 11:28

gregster wrote:
18 Jan 2021, 11:26
BoBo wrote:
18 Jan 2021, 11:25
boiler wrote:
18 Jan 2021, 11:18
Use Cancel instead of Destroy.
Shouldn't he 'hide' it instead? :think:
It's the same: https://www.autohotkey.com/docs/commands/Gui.htm#Cancel
:thumbup: wasn't really aware of that, Thx :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, ShatterCoder and 310 guests