Need to FileAppend instead of display Msgbox using checkboxs Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Need to FileAppend instead of display Msgbox using checkboxs

17 Oct 2017, 14:47

I couldnt figure out this myself :cry:

i would like to FileAppend to a text file the name of the checkbox(s) that seleced.
so for example if i would check "msg1" & "msg2" it'll append the text of the seletced checkboxs to a txt file,
like this: FileAppend, Msg1 Msg2, c:\test.txt instead showing it in a msgbox like it is now.

and so on..

my code:

Code: Select all

#NoEnv
#SingleInstance, Force

Gui, Add, CheckBox, x15 y18 w100 h23, Msg1
Gui, Add, CheckBox, x16 y54 w100 h23, Msg2
Gui, Add, CheckBox, x16 y90 w100 h23, Msg3
Gui, Add, CheckBox, x16 y120 w100 h23, Msg4
Gui, Add, Button, x128 y34 w75 h23, OK
Gui, Show, w217 h150
Return


ButtonOK:

    GuiControlGet, CHK_1,, Button1
    ControlGetText, TXT_1, Button1
    GuiControlGet, CHK_2,, Button2
    ControlGetText, TXT_2, Button2
	GuiControlGet, CHK_3,, Button3
    ControlGetText, TXT_3, Button3
	GuiControlGet, CHK_4,, Button4
    ControlGetText, TXT_4, Button4

    If (CHK_1 || CHK_2 || CHK_3 || CHK_4)
        MsgBox, % (CHK_1 ? TXT_1 "`n" : "")
                . (CHK_2 ? TXT_2 "`n" : "")
                . (CHK_3 ? TXT_3 "`n" : "")
                . (CHK_4 ? TXT_4 "`n" : "")
    Else
        MsgBox, Nothing selected
Return


GuiEscape:
GuiClose:
ExitApp
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Need to FileAppend instead of display Msgbox using checkboxs  Topic is solved

17 Oct 2017, 15:11

Code: Select all

#SingleInstance, Force
#NoEnv

Checked := ""

Gui, Add, CheckBox, x15 y18 w100 h23 vCheck1, Msg1
Gui, Add, CheckBox, x16 y54 w100 h23 vCheck2, Msg2
Gui, Add, CheckBox, x16 y90 w100 h23 vCheck3, Msg3
Gui, Add, CheckBox, x16 y120 w100 h23 vCheck4, Msg4
Gui, Add, Button, x128 y34 w75 h23 gButtonOK, OK
Gui, Show, w217 h150
return

ButtonOK:
    Gui, Submit, NoHide

    ControlGetText, TXT1, Button1
    ControlGetText, TXT2, Button2
    ControlGetText, TXT3, Button3
    ControlGetText, TXT4, Button4

    Loop, 4 {
        If (Check%A_Index%) {
            Checked .= TXT%A_Index% " "
        }
    }

    FileAppend, % Checked "`n", C:\test.txt

    Checked := ""
return

GuiEscape:
GuiClose:
    ExitApp
return
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: Need to FileAppend instead of display Msgbox using checkboxs

19 Oct 2017, 02:47

another option (tnx to wolf):

Code: Select all

#NoEnv
#SingleInstance, Force

Gui, Add, CheckBox, x15 y18 w100 h23, Msg1
Gui, Add, CheckBox, x16 y54 w100 h23, Msg2
Gui, Add, CheckBox, x16 y90 w100 h23, Msg3
Gui, Add, CheckBox, x16 y120 w100 h23, Msg4
Gui, Add, Button, x128 y34 w75 h23, OK
Gui, Show, w217 h150
Return


ButtonOK:

    GuiControlGet, CHK_1,, Button1
    ControlGetText, TXT_1, Button1
    GuiControlGet, CHK_2,, Button2
    ControlGetText, TXT_2, Button2
	GuiControlGet, CHK_3,, Button3
    ControlGetText, TXT_3, Button3
	GuiControlGet, CHK_4,, Button4
    ControlGetText, TXT_4, Button4

    If (CHK_1 || CHK_2 || CHK_3 || CHK_4)
        Msg := (CHK_1 ? TXT_1 "`n" : "")
             . (CHK_2 ? TXT_2 "`n" : "")
             . (CHK_3 ? TXT_3 "`n" : "")
             . (CHK_4 ? TXT_4 "`n" : "")
    Else
        Msg := "Nothing selected"

    FileAppend, %Msg%, c:\test.txt

Return


GuiEscape:
GuiClose:
ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 148 guests