if box is checked move a file to startup Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
mshall
Posts: 35
Joined: 13 Jul 2018, 16:42
GitHub: MattAHK

if box is checked move a file to startup

19 Jul 2018, 12:07

Hello,

I have a GUI that has some check boxes on a page. They will each do something different, but this one needs to move a file I have titled bob.lnc (it's a shortcut) to my startup folder. I have tried some variations of this, even trying FileCreateShortcut and making a new one. My original testing was done with just the message boxes, which all change on command perfectly.

Thank you for your help!

Code: Select all

Gui, Add, CheckBox, x94 y179 w310 h30 vCheckOne , button that changes different file to start folder
Gui, Add, CheckBox, x94 y239 w310 h30 vCheckTwo , boxname2
Gui, Add, Button, x195 y289 w100 h30 , Finish
Gui, Show, x467 y200 h399 w499, New GUI Window
Return
...
ButtonFinish:
gui, submit, nohide
BoxesChecked = 0 ;counter for number of boxes / which boxes are checked
if (CheckOne = 1)
	BoxesChecked += 1 ;only 1 box is checked
if (CheckTwo = 1)
	BoxesChecked += 2 ;a second box is checked, so to indicate it is different from 1 box, it is += 2
if (BoxesChecked = 1)
	MsgBox, moving to startup
	FileMove, %A_WorkingDir%\bob.lnc, C:\Users\mhall\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\ ; needs to be changed to general startup folder instead of users\mhall
if (BoxesChecked = 2)
	MsgBox, you selected 2
if (BoxesChecked = 3) ;if both are checked 1+2=3. If you had 3 boxes, this would be 6 because 1+2+3=6 or variations of 
	MsgBox, you selected both
;ExitApp
return
User avatar
mshall
Posts: 35
Joined: 13 Jul 2018, 16:42
GitHub: MattAHK

Re: if box is checked move a file to startup  Topic is solved

19 Jul 2018, 15:51

Needed to set working dir
User avatar
gregster
Posts: 1481
Joined: 30 Sep 2013, 06:48

Re: if box is checked move a file to startup

19 Jul 2018, 16:03

If your if block contains more than one line, you will have to use {...} - indenting will not help with this.
At the moment the line FileMove, %A_WorkingDir%\bob.lnc, C:\Users\mhall\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\ will always be executed unconditionally, each time the labeled subroutine runs...
User avatar
mshall
Posts: 35
Joined: 13 Jul 2018, 16:42
GitHub: MattAHK

Re: if box is checked move a file to startup

20 Jul 2018, 08:27

I noticed that and resolved it. Good to point out for future forum searches. If anyone does have questions, I am happy to take PMs.

Here was the final code used:

Code: Select all

SetWorkingDir %A_ScriptDir% ;sets current directory as working directory

Gui, Add, CheckBox, x94 y179 w310 h30 vCheckOne , your text here
Gui, Add, CheckBox, x94 y239 w310 h30 vCheckTwo , your text here 2
Gui, Add, Button, x195 y289 w100 h30 , Finish
Gui, Show, x467 y200 h399 w499, New GUI Window
Return

ButtonFinish:
{
gui, submit, nohide
BoxesChecked = 0 ;counter for number of boxes / which boxes are checked
if (CheckOne = 1)
	BoxesChecked += 1 ;only 1 box is checked
if (CheckTwo = 1)
	BoxesChecked += 2 ;a second box is checked, so to indicate it is different from 1 box, it is += 2
if (BoxesChecked = 1){
	FileMove, %A_WorkingDir%\bob.txt, C:\Users\%A_UserName%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\
	}
if (BoxesChecked = 2){
	Run, %A_WorkingDir%\license.txt, %A_WorkingDir%\
	return
	}
if (BoxesChecked = 3){ ;if both are checked 1+2=3. If you had 3 boxes, this would be 6 because 1+2+3=6 or variations of 
	FileMove, %A_WorkingDir%\bob.txt, C:\Users\%A_UserName%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\
	Run, %A_WorkingDir%\license.txt, %A_WorkingDir%\
	return
	}
ExitApp
}
return

Return to “Ask For Help”

Who is online

Users browsing this forum: aquadrious, sandym and 91 guests