Using loops and GUI together

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TASan
Posts: 23
Joined: 22 Feb 2016, 10:51

Using loops and GUI together

28 Aug 2017, 05:53

I am kind of lost. I don't have much experience in coding, so I can't see what is wrong here. What I want to do is the following.

1. Open a date picker
2. Save the picked date in a variable
3. Open the date picker again
4. Save the picked date in another variable

Exit the loop. The goal is to be able to pick a start and end date, and get each date in a separate variable. What I have so far does not work and nags me about having a "Return" before the "}", but doing that only breaks the loop. Also, have I named this second GUI correctly since I have the same GUI earlier in the script?

Code: Select all

^T::
loopcount = 0

Loop, 2 
{
  loopcount += 1
  Gui, 2:Add, MonthCal, xDate 
  Gui, 2:Add, Button,Default,OK 
  Gui, 2:Show, x800 y200, coolgui
  WinWaitClose, coolgui
  Gui, Destroy
2ButtonOK:
Gui,Submit 
FormatTime, dato, %date%, dd.MM.yy
dato%loopcount% = %dato%
}

MsgBox % dato1
MsgBox % dato2
Return
Any help would be greatly appreciated!
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Using loops and GUI together

28 Aug 2017, 07:11

Move your 2ButtonOK subroutine to the bottom of your script, outside of the loop and hotkey subroutine (after the Return), then you can put a Return on the end of it.
TASan
Posts: 23
Joined: 22 Feb 2016, 10:51

Re: Using loops and GUI together

28 Aug 2017, 07:30

Thank you for answering, that worked in getting rid of the error :)

But I now have the problem that the date that is shown in the message box for "dato1" and "dato2" is todays date in both, and not the dates I choose in the two GUI's. I have examined the code but can't explain why?

Maybe you have some tips here too? :)
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Using loops and GUI together

28 Aug 2017, 07:37

Doesn't your Gui, Submit need to be Gui, 2:Submit? Not sure if that fixes it, but it seems like at least one problem.
TASan
Posts: 23
Joined: 22 Feb 2016, 10:51

Re: Using loops and GUI together

28 Aug 2017, 07:53

That is probably true. I changed it, but it did not do anything. I found that the following might cause a problem?

Code: Select all

Gui, 2:Add, MonthCal, xDate
Is probably should be this?

Code: Select all

Gui, 2:Add, MonthCal, vDate
But then I get an error stating that I can't have the same variable for more than one control...
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Using loops and GUI together

28 Aug 2017, 09:35

Change it to this:
Gui, 2:Add, MonthCal, vDate%loopcount%

And also change the format line to this:
FormatTime, dato, % date%loopcount%, dd.MM.yy
TASan
Posts: 23
Joined: 22 Feb 2016, 10:51

Re: Using loops and GUI together

29 Aug 2017, 00:58

Thank you so much for helping me in this, I am so close to getting this correct. The only problem now is that the second date always is today's date no matter what I choose in the second GUI that pops up. I have changed some variable names now to make the code more clear, and I would be really glad if you could perhaps look at this one more time.

Code: Select all

^T::
loopcount = 0

Loop, 2 
{
  loopcount += 1
  Gui, 2:Add, MonthCal, vDate%loopcount% 
  Gui, 2:Add, Button,Default,OK 
  Gui, 2:Show, x800 y200, coolgui
  WinWaitClose, coolgui
  Gui, Destroy
}

MsgBox % newDate1
MsgBox % newDate2
Return

2ButtonOK:
Gui, 2:Submit 
FormatTime, dato, % date%loopcount%, dd.MM.yy
newDate%loopcount% = %dato%
Return
Thanks!
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: Using loops and GUI together

29 Aug 2017, 01:44

You forgot 2 in destroy change your code to: Gui, 2:Destroy and everything will work.
TASan
Posts: 23
Joined: 22 Feb 2016, 10:51

Re: Using loops and GUI together

29 Aug 2017, 01:50

You guys are just amazing!!

Thanks, it all works!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Giresharu, Google [Bot], mikeyww, supplementfacts and 169 guests