Loop dropdownlist + send value based on total amount of values insterted Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Johana
Posts: 189
Joined: 02 May 2017, 02:34

Loop dropdownlist + send value based on total amount of values insterted

23 Feb 2018, 09:21

At our shelter we have a application that people send to us. They can apply up to 10 (currently in the GUI it's 5) dates where they can have a temporary home for a dog.
They will either be granted some of the dates (never all) or will be declined all of the dates.

After submit I want it to display all dates that has been applied and also all dates that has been rejected. If there's more then 1 date picked I want it to add a "and" before the last date:
You have applied for date1 to date2, date3 to date4 and date5 to date6.

Declined dates: date1 to date2 and date5 to date6.
Below is the gui + the loop I had in mind

Code: Select all

#NoEnv
#Singleinstance, Force
Periods := "1"
loop, 5 ; Change based on how many Dropdownlist values should be shown
	DDLCount .= A_Index "|"

	TopOfScript:
	Gui, KAnf:Color, AAAAAA

	
Gui, KAnF:Add, text, cblack section xm w200, Pick a value
Gui, KAnF:Add, DropDownList, w200 vChosenValue R4 choose1, Name|A user|Setting|Dog|Cat|Animal
Gui, KAnF:Add, text, ys cblack w250 vRedanFatt, Have the user applied before?
Gui, KAnF:Add, DropDownList, w250 vFaettErsatt R2 choose1, Applied|Application sent
Gui, KAnF:Add, text, section xm cblack w200 vKonsekvens, What's the consequence?
Gui, KAnF:Add, DropDownList, w200 vHelDelDecline gToggle R2 choose1, Total Decline|Part Decline
Gui, KAnF:Add, text, ys cblack w200, What is the applicants name?
Gui, KAnF:Add, edit, w250 vApplicantName
Gui, KAnF:add, Text, section xm cblack, How many periods (Decline): 
Gui, KAnF:add, DropDownList, ys-3 gOK2 choose%Periods% vPeriods w50, %DDLCount%
loop, %Periods%
{	
	Gui, KAnF:add, Text, section xm cblack, Period %A_Index%:
	Gui, KAnF:add, DateTime, section xm w160 vPeriodA%A_Index%
	Gui, KAnF:add, text, ys+3 cblack, to
	Gui, KAnF:add, DateTime, ys w160 vPeriodB%A_Index%
	Gui, KAnF:add, CheckBox, ys cblack vCheckbox%A_Index%, Decline?
}
Gui, KAnF:add, dropdownlist, vJournal choose1 section xm y+15 w405, Word Journal|Send a letter|Nothing
Gui, KAnF:add, button, section xm vOK gOK default, OK
Gui, KAnF:add, button, ys, Reload

Gui, KAnF:Show,autosize, Some testing
return

KAnFGuiClose:
KAnFGuiEsc:
ExitApp
return

KAnFButtonReload:
reload
return

Toggle:
Gui, KAnF: Submit, NoHide
if (HelDelDecline = "Total Decline") {
GuiControl, KAnF: disabled, PeriodssattText
GuiControl, KAnF: disabled, Periodssatt
} else {
GuiControl, KAnF: enabled, PeriodssattText
GuiControl, KAnF: enabled, Periodssatt
}
return


OK2:
OK3:
Gui, KAnF: Submit
Gui, KAnF: destroy
Goto, TopOfScript
return
 
OK:
Gui, KAnF: Submit
ExitApp

Code: Select all

Periods := "4"
Checkbox1 := "1"
Checkbox2 := "0"
Checkbox3 := "1"
Checkbox4 := "0"
loop, %Periods%
{
PeriodA%A_Index% := "2018-02-1" . A_Index
PeriodB%A_Index% := "2018-02-2" . A_Index
}
loop, %Periods%
{
AllPeriods .= PeriodA%A_Index% " to " PeriodB%A_Index%
If % Checkbox%A_Index% = 1
PeriodsDecline .= PeriodA%A_Index% " to " PeriodB%A_Index%
else
PeriodsGranted .= PeriodA%A_Index% " to " PeriodB%A_Index%
}
Msgbox % AllPeriods
Msgbox % PeriodsDecline
Msgbox % PeriodsGranted   
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Loop dropdownlist + send value based on total amount of values insterted  Topic is solved

23 Feb 2018, 10:48

Try this.

Code: Select all

OK:
Gui, KAnF: Submit, NoHide
strDat := "You have applied for ", strDecl := "Declined dates: "
loop, %Periods% {
	FormatTime,dateA, % periodA%A_index%, yyyy-MM-dd
	FormatTime,dateB, % periodB%A_index%, yyyy-MM-dd
	strDat .= dateA " to " dateB ", " 		
	if ( Checkbox%A_index%)
		strDecl .= dateA " to " dateB ", " 		
}
strDat :=  RegExReplace(substr(strDat,1,-2), ",\s([\d-]+ to [\d-]+)$"," and $1")
strDecl :=  RegExReplace(substr(strDecl,1,-2), ",\s([\d-]+ to [\d-]+)$"," and $1")
MsgBox % strDat "`n" strDecl
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
TQu

Re: Loop dropdownlist + send value based on total amount of values insterted

23 Feb 2018, 16:02

Code: Select all

Periods := "1"
Checkbox1 := "1"
Checkbox2 := "0"
Checkbox3 := "1"
Checkbox4 := "0"
loop, %Periods%
{
	PeriodA%A_Index% := "2018-02-1" . A_Index
	PeriodB%A_Index% := "2018-02-2" . A_Index
}
loop, %Periods%
{	if (a_index<=Periods-2){
		AllPeriods .= PeriodA%A_Index% " to " PeriodB%A_Index% ", "
		If % Checkbox%A_Index% = 1
			PeriodsDecline .= PeriodA%A_Index% " to " PeriodB%A_Index%
		else
			PeriodsGranted .= PeriodA%A_Index% " to " PeriodB%A_Index%
	}
	if (a_index=Periods-1){
		AllPeriods .= PeriodA%A_Index% " to " PeriodB%A_Index% " and "
	}
	if (a_index=Periods){
		AllPeriods .= PeriodA%A_Index% " to " PeriodB%A_Index%
	}
}

Msgbox % AllPeriods
; etc
Johana
Posts: 189
Joined: 02 May 2017, 02:34

Re: Loop dropdownlist + send value based on total amount of values insterted

23 Feb 2018, 17:18

Odlanir wrote:Try this.

Code: Select all

OK:
Gui, KAnF: Submit, NoHide
strDat := "You have applied for ", strDecl := "Declined dates: "
loop, %Periods% {
	FormatTime,dateA, % periodA%A_index%, yyyy-MM-dd
	FormatTime,dateB, % periodB%A_index%, yyyy-MM-dd
	strDat .= dateA " to " dateB ", " 		
	if ( Checkbox%A_index%)
		strDecl .= dateA " to " dateB ", " 		
}
strDat :=  RegExReplace(substr(strDat,1,-2), ",\s([\d-]+ to [\d-]+)$"," and $1")
strDecl :=  RegExReplace(substr(strDecl,1,-2), ",\s([\d-]+ to [\d-]+)$"," and $1")
MsgBox % strDat "`n" strDecl
Thanks you O and thank you TQU.

Odlanir, you are a hero aren't you? Thanks!

May I, if you have time, ask you to explain the following to rows or point me in the direction where I can learn what it means?
strDat := RegExReplace(substr(strDat,1,-2), ",\s([\d-]+ to [\d-]+)$"," and $1")
strDecl := RegExReplace(substr(strDecl,1,-2), ",\s([\d-]+ to [\d-]+)$"," and $1")
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Loop dropdownlist + send value based on total amount of values insterted

23 Feb 2018, 17:54

you say:
If there's more then 1 date picked I want it to add a "and" before the last date:
Since the loop creates a string appending to each couple of periods a comma and a space, the resulting final string will terminate with those two chars.
So the

Code: Select all

substr(strDat,1,-2)
will eliminate it.
Then the regexreplace will replace the last remaining occurrence of the above mentioned chars with " and " to produce the expected result.
The pattern

Code: Select all

",\s([\d-]+ to [\d-]+)$"
searchs for a comma followed by a blank followed by a string composed only of digits and the char "-" followed by a blank, by the string "to" and by another blank followed by a string composed only of digits and the char "-", at the end of the original string using the anchor $. All between the parenthesis will be saved in $1.
The pattern

Code: Select all

" and $1"
replace all the previous pattern with a blank followed by the string "and" followed by a blank and finally by what was found previously between parenthesis ( $1).
Hope this make sense.
Cheers.

Sorry for my bad english.
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, OrangeCat, ShatterCoder and 91 guests