Checkbox to Edit

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dellarocco88
Posts: 35
Joined: 07 Apr 2022, 01:34

Checkbox to Edit

Post by dellarocco88 » 27 May 2022, 16:46

What I want is to send the checked movies to the vEdit with a movie on a new line for every movie.
I know I can do with Guicontrol, but there I need all the possible combinations, can I do it on a easy way?

Code: Select all

^!a::
Gui, Font, s10
Gui, 1:Add, Text, x10 y10, What movie?
Gui, 1:Add, Edit, vEdit r4, 
Gui, 1:Add, Button, gVar, Pick 

Gui, 1:+AlwaysOnTop
Gui, 1:Show, x500 y500 w300 h300, Movies
return

Var:
Gui, Submit, Nohide
Gui, 2:Add, Checkbox,,Saving Privet Ryan
Gui, 2:Add, Checkbox,,Leon
Gui, 2:Add, Checkbox,,The Boondock Saints
Gui, 2:Add, Checkbox,,Titanic

Gui, 2:Add, Button, gRad, Send

Gui, 2:+AlwaysOnTop
Gui, 2:Show, x500 y500 w300 h300, Movies
return

Rad:
???????

Ianizer
Posts: 79
Joined: 07 Mar 2021, 00:06

Re: Checkbox to Edit

Post by Ianizer » 27 May 2022, 18:27

Here's a possibility:

Code: Select all

^!a::
Gui, Font, s10
Gui, 1:Add, Text, x10 y10, What movie?
Gui, 1:Add, Edit, vEdit r4, 
Gui, 1:Add, Button, gVar, Pick 

Gui, 1:+AlwaysOnTop
Gui, 1:Show, x500 y500 w300 h300, Movies
return

Var:
Gui, Submit, Nohide
Gui, 2:Add, Checkbox, vMovie1, Saving Privet Ryan ;give each movie checkbox a variable called "Movie" with the number checkbox it is, like so.
Gui, 2:Add, Checkbox, vMovie2, Leon
Gui, 2:Add, Checkbox, vMovie3, The Boondock Saints
Gui, 2:Add, Checkbox, vMovie4, Titanic

NumberOfMovies := 4 ;change the 4 if you add/remove movies.

Gui, 2:Add, Button, gRad, Send

Gui, 2:+AlwaysOnTop
Gui, 2:Show, x500 y500 w300 h300, Movies
return

Rad:
	Gui, 2:Submit

	Loop, % NumberOfMovies
	{
		if (Movie%A_Index%) ;if the current movie checkbox is checked
		{
			GuiControlGet, NameOfMovie, 2:, Movie%A_Index%, Text ;get name of movie
			ListOfMovies .= ((ListOfMovies) ? ("`n") : ("")) NameOfMovie ;add name of movie on a new line to ListOfMovies
		}
	}

	GuiControl, 1:, Edit, % ListOfMovies
	ListOfMovies := ""
return

dellarocco88
Posts: 35
Joined: 07 Apr 2022, 01:34

Re: Checkbox to Edit

Post by dellarocco88 » 30 May 2022, 05:17

Thanks man! Works like a charm, well done! :)

The only thing that don't work is if I wanna change the list, with that I meen open the list again efter already selected movies, it don't work.
Tried to do this to reset the checkboxes but don't work.
AvvBedömningalt1:
Gui, Submit, Nohide
GuiControl,2:,Movie1,0
GuiControl,2:,Movie2,0
GuiControl,2:,Movie3,0
GuiControl,2:,Movie4,0

User avatar
boiler
Posts: 16912
Joined: 21 Dec 2014, 02:44

Re: Checkbox to Edit

Post by boiler » 30 May 2022, 05:46

Those lines do work. They would clear the checkboxes if you executed them. What did you do in your script to execute those lines? (i.e., where did you put them, and how did you route the execution flow to them?)

There is no reason for the Gui, Submit, Nohide line there, at least not for clearing the checkboxes.

dellarocco88
Posts: 35
Joined: 07 Apr 2022, 01:34

Re: Checkbox to Edit

Post by dellarocco88 » 30 May 2022, 07:34

Sry, here's the full code :)
Still says that "The same variable cannot be used for more than one control"

Code: Select all

^!a::
Gui, Font, s10
Gui, 1:Add, Text, x10 y10, What movie?
Gui, 1:Add, Edit, vEdit r4, 
Gui, 1:Add, Button, gVar, Pick 

Gui, 1:+AlwaysOnTop
Gui, 1:Show, x500 y500 w300 h300, Movies
return

Var:
Gui, Submit, Nohide
GuiControl,2:,Movie1,0
GuiControl,2:,Movie2,0
GuiControl,2:,Movie3,0
GuiControl,2:,Movie4,0
Gui, 2:Add, Checkbox, vMovie1, Saving Privet Ryan ;give each movie checkbox a variable called "Movie" with the number checkbox it is, like so.
Gui, 2:Add, Checkbox, vMovie2, Leon
Gui, 2:Add, Checkbox, vMovie3, The Boondock Saints
Gui, 2:Add, Checkbox, vMovie4, Titanic

NumberOfMovies := 4 ;change the 4 if you add/remove movies.

Gui, 2:Add, Button, gRad, Send

Gui, 2:+AlwaysOnTop
Gui, 2:Show, x500 y500 w300 h300, Movies
return

Rad:
Gui, 2:Submit
Loop, % NumberOfMovies
	{
	if (Movie%A_Index%) ;if the current movie checkbox is checked
		{
		GuiControlGet, NameOfMovie, 2:, Movie%A_Index%, Text ;get name of movie
		ListOfMovies .= ((ListOfMovies) ? ("`n") : ("")) NameOfMovie ;add name of movie on a new line to ListOfMovies
		}
	}

GuiControl, 1:, Edit, % ListOfMovies
ListOfMovies := ""
return

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Checkbox to Edit

Post by BoBo » 30 May 2022, 08:13

I seem to remember that this "event" has been already explained to you in another thread!? Calling/executing/building/creating the GUI for consecutive times using a hotkey means you're trying to initialize/declaring that one single variable named "Edit" again and again, which is kinda stupid bc it's already existing, and therefore any attempts to create "copies" of it is illegal. If you want to use the same (already existing) GUI consecutive times combined with a hotkey, use it to explicitly Show/Hide the GUI, not to create it. Otherwise, you've to destroy an already existing GUI beforehand. :eh:

User avatar
boiler
Posts: 16912
Joined: 21 Dec 2014, 02:44

Re: Checkbox to Edit

Post by boiler » 30 May 2022, 08:47

In this case, it is reasonable to address both issues (both clearing the checkboxes and not reusing the same variables) by destroying the GUI and recreating it:

Code: Select all

^!a::
Gui, Font, s10
Gui, 1:Add, Text, x10 y10, What movie?
Gui, 1:Add, Edit, vEdit r4, 
Gui, 1:Add, Button, gVar, Pick 

Gui, 1:+AlwaysOnTop
Gui, 1:Show, x500 y500 w300 h300, Movies
return

Var:
Gui, 2:Destroy
Gui, 2:Add, Checkbox, vMovie1, Saving Privet Ryan ;give each movie checkbox a variable called "Movie" with the number checkbox it is, like so.
Gui, 2:Add, Checkbox, vMovie2, Leon
Gui, 2:Add, Checkbox, vMovie3, The Boondock Saints
Gui, 2:Add, Checkbox, vMovie4, Titanic

NumberOfMovies := 4 ;change the 4 if you add/remove movies.

Gui, 2:Add, Button, gRad, Send

Gui, 2:+AlwaysOnTop
Gui, 2:Show, x500 y500 w300 h300, Movies
return

Rad:
Gui, 2:Submit
Loop, % NumberOfMovies
	{
	if (Movie%A_Index%) ;if the current movie checkbox is checked
		{
		GuiControlGet, NameOfMovie, 2:, Movie%A_Index%, Text ;get name of movie
		ListOfMovies .= ((ListOfMovies) ? ("`n") : ("")) NameOfMovie ;add name of movie on a new line to ListOfMovies
		}
	}

GuiControl, 1:, Edit, % ListOfMovies
ListOfMovies := ""
return

In general, however, you should follow BoBo's direction and only create the GUI once and use only Gui, Show when the event is triggered.

dellarocco88
Posts: 35
Joined: 07 Apr 2022, 01:34

Re: Checkbox to Edit

Post by dellarocco88 » 30 May 2022, 09:02

Yes you did BoBo and the fault is on my side big time! I put in the destroy, but the problem was that I were running two scipts with the same variable inside... so as I said, my bad :silent:
Works fine now thu! :)

Once again, thanks for the answers, helps ALOT!

Can't say I understand 100% how this line works :eh: Understands what i does, but not how?

Code: Select all

ListOfMovies .= ((ListOfMovies) ? ("`n") : ("")) NameOfMovie

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Checkbox to Edit

Post by BoBo » 30 May 2022, 09:09

@dellarocco88 :arrow: ternary operator

Post Reply

Return to “Ask for Help (v1)”