Help finding what I did wrong in script Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Milenko
Posts: 11
Joined: 18 Sep 2019, 15:20

Help finding what I did wrong in script

24 Sep 2019, 15:43

I started building what i thought would be a fairly easy and simple script for a newb like myself. All was going well untill i decided to clean up the code and add a few things.
Now my second version won't work. I'm completely lost. :headwall:

Any advice and help would be greatly appreciated!

First version that works:

Code: Select all

Gui, +AlwaysOnTop


Gui, Add, Edit, vLine1
Gui, Add, Edit, vLine2
Gui, Add, Edit, vLine3


Gui, Add, Edit, vTime1  ym
Gui, Add, Edit, vTime2
Gui, Add, Edit, vTime3

Gui, Add, Button, default, OK  
Gui, Show,, autosend
return  

GuiClose:
ButtonOK:
Gui, Submit  

MsgBox, 4,, are you sure you want to run autosend? (Esc will Exit / F7 will Pause)
IfMsgBox Yes
Loop
{



Send,  %Line1%{ENTER}
Sleep, %Time1%000

Send,  %Line2%{ENTER}
Sleep, %Time2%000

Send,  %Line3%{ENTER}
Sleep, %Time3%000

}

else
ExitApp


return


F7::PAUSE
return


Esc::
ExitApp
return
Second version that Does Not work:

Code: Select all

Gui, +AlwaysOnTop
Gui, color, 000000
Gui, Font, cWhite
Gui, color,, 000000

Gui, Add, Text, x12 y9 w100 h20 , Message
Gui, Add, Text, x142 y9 w100 h20 , Seconds

Gui, Add, Edit, x12 y29 w100 h30 vLine1, 1
Gui, Add, Edit, x12 y69 w100 h30 vLine2, 2
Gui, Add, Edit, x12 y109 w100 h30 vLine3, 3
Gui, Add, Edit, x12 y149 w100 h30 vLine4, 4
Gui, Add, Edit, x12 y189 w100 h30 vLine5, 5


Gui, Add, Edit, x142 y29 w100 h30 vTime1, 6
Gui, Add, Edit, x142 y69 w100 h30 vTime2, 7
Gui, Add, Edit, x142 y149 w100 h30 vTime3, 8
Gui, Add, Edit, x142 y109 w100 h30 vTime4, 9
Gui, Add, Edit, x142 y189 w100 h30 vTime5, 10


Gui, Add, Button, x12 y229 w100 h30 , OK
Gui, Add, Button, x142 y229 w100 h30 , Stop
Gui, Add, Button, x12 y269 w100 h30 , Pause
Gui, Add, Button, x142 y269 w100 h30 , Help

Gui, Show, x500 y100 h353 w258, AutoSend



ButtonOK:
Sleep, 3000
Send,  %Line1%{ENTER}
Sleep, %Time1%000

Send,  %Line2%{ENTER}
Sleep, %Time2%000

Send,  %Line3%{ENTER}
Sleep, %Time3%000

Send,  %Line4%{ENTER}
Sleep, %Time4%000

Send,  %Line5%{ENTER}
Sleep, %Time5%000
return


ButtonStop:
ExitApp
return

ButtonPause:
Pause, Toggle
return

ButtonHelp:
Gui +OwnDialogs
OnMessage(0x44, "OnMsgBox")
MsgBox 0x40000, Help, help message will go here
OnMessage(0x44, "")

OnMsgBox() {
    DetectHiddenWindows, On
    Process, Exist
    If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
        ControlSetText Button1, Close
        WinMove 900, 175
    }
}
return

Esc::Exitapp
return

F7::
Pause, Toggle
return

GuiClose:
exitapp
return
ilhom
Posts: 52
Joined: 19 Aug 2019, 17:58

Re: Help finding what I did wrong in script  Topic is solved

24 Sep 2019, 16:28

2 problems.
1) You need to add a return after you finish creating the GUI.
2) Need a Gui, Submit for the OK button in order for those variables to obtain their submitted value in the GUI.

Code below has those fixes.

Code: Select all

Gui, +AlwaysOnTop
Gui, color, 000000
Gui, Font, cWhite
Gui, color,, 000000

Gui, Add, Text, x12 y9 w100 h20 , Message
Gui, Add, Text, x142 y9 w100 h20 , Seconds

Gui, Add, Edit, x12 y29 w100 h30 vLine1, 1
Gui, Add, Edit, x12 y69 w100 h30 vLine2, 2
Gui, Add, Edit, x12 y109 w100 h30 vLine3, 3
Gui, Add, Edit, x12 y149 w100 h30 vLine4, 4
Gui, Add, Edit, x12 y189 w100 h30 vLine5, 5


Gui, Add, Edit, x142 y29 w100 h30 vTime1, 6
Gui, Add, Edit, x142 y69 w100 h30 vTime2, 7
Gui, Add, Edit, x142 y149 w100 h30 vTime3, 8
Gui, Add, Edit, x142 y109 w100 h30 vTime4, 9
Gui, Add, Edit, x142 y189 w100 h30 vTime5, 10


Gui, Add, Button, x12 y229 w100 h30 , OK
Gui, Add, Button, x142 y229 w100 h30 , Stop
Gui, Add, Button, x12 y269 w100 h30 , Pause
Gui, Add, Button, x142 y269 w100 h30 , Help

Gui, Show, x500 y100 h353 w258, AutoSend

return

ButtonOK:
Gui, Submit
Sleep, 3000
Send,  %Line1%{ENTER}
Sleep, %Time1%000

Send,  %Line2%{ENTER}
Sleep, %Time2%000

Send,  %Line3%{ENTER}
Sleep, %Time3%000

Send,  %Line4%{ENTER}
Sleep, %Time4%000

Send,  %Line5%{ENTER}
Sleep, %Time5%000
return


ButtonStop:
ExitApp
return

ButtonPause:
Pause, Toggle
return

ButtonHelp:
Gui +OwnDialogs
OnMessage(0x44, "OnMsgBox")
MsgBox 0x40000, Help, help message will go here
OnMessage(0x44, "")

OnMsgBox() {
    DetectHiddenWindows, On
    Process, Exist
    If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
        ControlSetText Button1, Close
        WinMove 900, 175
    }
}
return

Esc::Exitapp
return

F7::
Pause, Toggle
return

GuiClose:
exitapp
return
User avatar
Milenko
Posts: 11
Joined: 18 Sep 2019, 15:20

Re: Help finding what I did wrong in script

26 Sep 2019, 11:34

Thanks alot! :dance:

I tried with and without my Submit but completely forgot a return.

Return to “Ask For Help”

Who is online

Users browsing this forum: anv, AshleyM0101, coder_chick, DaveT1, Laser-Ben-2020, mikeyww, Soselo, TAC109 and 52 guests