Varying button names

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Shoal
Posts: 24
Joined: 26 Jul 2017, 16:28

Varying button names

31 Jul 2017, 11:37

I want to change the name of buttons based on what a user writes in a .txt file
Here is my code:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory

Gui, Add, Tab2, x0 y0 w200 h20, Songlist||Cycle|How to use
Gui, Show, w200 h225, Playlist
Gui +AlwaysOnTop

Gui, Tab, 1
Gui, Add, Picture, x0 y20 w200 h230, %A_ScriptDir%/Resources/Image1.png

Gui, Add, Button, x5 y20 w190 h20 gSongOne, Song 1
Gui, Add, Button, x5 y40 w190 h20 gSongTwo, Song 2
Gui, Add, Button, x5 y60 w190 h20 gSongThree, Song 3
Gui, Add, Button, x5 y80 w190 h20 gSongFour, Song 4
Gui, Add, Button, x5 y100 w190 h20 gSongFive, Song 5
Gui, Add, Button, x5 y120 w190 h20 gSongSix, Song 6
Gui, Add, Button, x5 y140 w190 h20 gSongSeven, Song 7
Gui, Add, Button, x5 y160 w190 h20 gSongEight, Song 8
Gui, Add, Button, x5 y180 w190 h20 gSongNine, Song 9
Gui, Add, Button, x5 y200 w190 h20 gStopSong, Stop

Gui, Tab, 2
Gui, Add, Picture, x0 y20 w200 h230, %A_ScriptDir%/Resources/Image1.png
Gui, Add, Button, x5 y20 w190 h20 gCycle, Cycle through all

Gui, Tab, 3
Gui, Add, Picture, x0 y20 w200 h230, %A_ScriptDir%/Resources/Image1.png

^0::
		SoundPlay, %A_ScriptDir%/Music/nonexistent.mp3
		return
SongOne:
		SoundPlay, %A_ScriptDir%/Music/Song1.mp3
		return
SongTwo:
		SoundPlay, %A_ScriptDir%/Music/Song2.mp3
		return
SongThree:
		SoundPlay, %A_ScriptDir%/Music/Song3.mp3
		return
SongFour:
		SoundPlay, %A_ScriptDir%/Music/Song4.mp3
		return
SongFive:
		SoundPlay, %A_ScriptDir%/Music/Song5.mp3
		return
SongSix:
		SoundPlay, %A_ScriptDir%/Music/Song6.mp3
		return
SongSeven:
		SoundPlay, %A_ScriptDir%/Music/Song7.mp3
		return
SongEight:
		SoundPlay, %A_ScriptDir%/Music/Song8.mp3
		return
SongNine:
		SoundPlay, %A_ScriptDir%/Music/Song9.mp3
		return
StopSong:
		SoundPlay, %A_ScriptDir%/Music/nonexistent.mp3
		return
^1::
		SoundPlay, %A_ScriptDir%/Music/Song1.mp3
		return
^2::
		SoundPlay, %A_ScriptDir%/Music/Song2.mp3
		return
^3::
		SoundPlay, %A_ScriptDir%/Music/Song3.mp3
		return
^4::
		SoundPlay, %A_ScriptDir%/Music/Song4.mp3
		return
^5::
		SoundPlay, %A_ScriptDir%/Music/Song5.mp3
		return
^6::
		SoundPlay, %A_ScriptDir%/Music/Song6.mp3
		return
^7::
		SoundPlay, %A_ScriptDir%/Music/Song7.mp3
		return
^8::
		SoundPlay, %A_ScriptDir%/Music/Song8.mp3
		return
^9::
		SoundPlay, %A_ScriptDir%/Music/Song9.mp3
		return
Cycle:
	Loop
	{
	SoundPlay, %A_ScriptDir%/Music/Song1.mp3, 1
	SoundPlay, %A_ScriptDir%/Music/Song2.mp3, 1
	SoundPlay, %A_ScriptDir%/Music/Song3.mp3, 1
	SoundPlay, %A_ScriptDir%/Music/Song4.mp3, 1
	SoundPlay, %A_ScriptDir%/Music/Song5.mp3, 1
	SoundPlay, %A_ScriptDir%/Music/Song6.mp3, 1
	SoundPlay, %A_ScriptDir%/Music/Song7.mp3, 1
	SoundPlay, %A_ScriptDir%/Music/Song8.mp3, 1
	SoundPlay, %A_ScriptDir%/Music/Song9.mp3, 1
	}

	return
	
Delete::ExitApp
I appreciate any help!
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Varying button names

31 Jul 2017, 16:07

You can use a .txt file with FileRead (and write to it using FileAppend). You may also consider using IniRead/IniWrite.
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Varying button names

31 Jul 2017, 19:20

GuiControl can be used to change the text of a Button after you get the info from the text file.

Code: Select all

Gui, Add, Button, x5 y20 w190 h20 gSongOne vSongOne, Song 1
Gui, Show

SongOne:
    GuiControl,, SongOne, New Song
return
When you click on the button the name will change to "New Song".

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Varying button names

01 Aug 2017, 07:23

IMHO, there's really a good chance to get rid of redundant code (sections).
Eg. have a start looking at A_GuiControl. Good luck :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 310 guests