I have a combo box with several peoples names in the list, the code I wrote works but it I duplicate the code for each person. How do I get each persons name to look at the part of the code that is the same? for example
current method
if person1
{
do this
do this
do this
email person1
}
if person2
{
do this
do this
do this
email person2
}
proposed way:
if person1
{
do function1
email person1
}
if person2
{
do function1
email person2
}
function1
{
do this
do this
do this
}
code once for 3 buttons
Re: code once for 3 buttons
Code: Select all
; store data
persons:={"john":"[email protected]","carol":"[email protected]"}
; make list for listbox
for k, v in persons
list .= k "|"
; demo gui
Gui, add, listbox, vPerson, %list%
Gui, add, button, gFunc, Submit
Gui, Show
Return
func:
Gui, submit
;do this
;do this
;do this
MsgBox % persons[Person] ; show email
ExitApp
Return
Re: code once for 3 buttons
(Codebox added)sbrady wrote:proposed way:Code: Select all
if person1 { do function1 email person1 } if person2 { do function1 email person2 } function1 { do this do this do this }
I don't see a problem with that pseudo-code. It looks like you do function1 regardless of the person, so that can be moved outside the if.
Code: Select all
function1()
if (person1)
{
;email person1
}
else if (person2)
{
;email person2
}
return
function1()
{
;do this
}
Re: code once for 3 buttons
thank you Kon, I think your plan is going to work.
; gail
; january
; may
; september
; interactive
; news
; audio ops
; studio 5
; turning point
emailSource = january
ifequal, emailSource, Gail
{
msgbox, gail
getinfo()
}
ifequal, emailSource, january
{
msgbox, january
getinfo()
}
getinfo()
{
FormatTime, CurrentDate,, MM-dd-yy ;04-24-17
msgbox, %CurrentDate%
}
return
; gail
; january
; may
; september
; interactive
; news
; audio ops
; studio 5
; turning point
emailSource = january
ifequal, emailSource, Gail
{
msgbox, gail
getinfo()
}
ifequal, emailSource, january
{
msgbox, january
getinfo()
}
getinfo()
{
FormatTime, CurrentDate,, MM-dd-yy ;04-24-17
msgbox, %CurrentDate%
}
return
Re: code once for 3 buttons
Kon, what if in getinfo() the last thing it does if have a variable with some value. call it....importantINFO.
How do I get (or call) the variable importantINFO in the Gail or January sections.
How do I get (or call) the variable importantINFO in the Gail or January sections.
Re: code once for 3 buttons
You'd better search the Help file first, and post questions.
AutoHotkey Beginner Tutorial
https://autohotkey.com/docs/Tutorial.htm
Function
https://autohotkey.com/docs/Tutorial.htm#s5
https://autohotkey.com/docs/Functions.htm
AutoHotkey Beginner Tutorial
https://autohotkey.com/docs/Tutorial.htm
Function
https://autohotkey.com/docs/Tutorial.htm#s5
https://autohotkey.com/docs/Functions.htm
Last edited by IMEime on 24 May 2017, 11:17, edited 2 times in total.
Re: code once for 3 buttons
Maybe
Code: Select all
if (emailSource = "gail")
{
msgbox, gail
}
else if (emailSource = "january")
{
msgbox, january
}
Var := getinfo()
MsgBox, % Var
return
getinfo()
{
FormatTime, CurrentDate,, MM-dd-yy ;04-24-17
return CurrentDate
}