Page 1 of 1

Problem with GUI Control

Posted: 09 Jan 2018, 16:38
by sttrebo
I've got a script in process where I want to change the text in a GUI.
https://www.dropbox.com/s/noqf9sgr8llnm ... e.JPG?dl=0

i want to be able to select a file and have the 'n/a' be replaced by the filename. must be having a brain f**t because i can't seem to get it working. can someone show me what i'm doing wrong?

Code: Select all

Link = n/a

Gui, Add, Button, gLink, File_Link
Gui, Add, Text,, %Link%

Gui, Show, w150 h220, QuickAdd ; was 190

GuiControl,, %Link%, %Link%

return

Link:
msgbox, %Link%
repl .= "%20"
FileSelectFile, Link
msgbox, %Link%
IfInString, Link, %A_Space%
	{
	StringReplace, newlink, Link, %A_Space%, %repl%, All
	}
	else
	{
	msgbox, %newlink%
	newlink = %Link%
	}
	msgbox, %Link%
	
return

exitapp

Re: Problem with GUI Control

Posted: 09 Jan 2018, 23:57
by GreatGazoo
try entering the path to the file, i have a hard time with GUI too i might not be any help at all, i have found just generally, when we call on scripts to retrieve something they'll need the path

just my thoughts, ive never attempted such things myself

example:

C:\Users\User A\Pictures\Saved Pictures

Code: Select all

:*:aa::
run, calc.exe
return
oh i think maybe i miss read your comment, you want to select a file and have that show in the gui, you might need that clipboard stuff, im not sure just highlighting something is enough, you should try the clipboard scripts, then you can highlight, copy, and you have it saved to clipboard for pasting in the "n/a" field.

Re: Problem with GUI Control

Posted: 10 Jan 2018, 01:56
by wolf_II
replace GuiControl,, %Link%, %Link%
with this GuiControl,, Link, %Link%

Re: Problem with GUI Control

Posted: 10 Jan 2018, 10:36
by sttrebo
thanks wolf_II, but doesn't seem to do anything. n/a stays n/a in the dialog box.

Re: Problem with GUI Control

Posted: 10 Jan 2018, 10:52
by just me
As is,

Code: Select all

GuiControl,, %Link%, %Link%
is executed only once when the script is started. So how would the control's contents be changed?

Re: Problem with GUI Control

Posted: 10 Jan 2018, 11:11
by sttrebo
my bad, this seems to work as I need. one thing though: when the n/a field is changed to the %Link% contents, the length of the field doesn't automatically change with the length of the variable. How can I make the length change as the length of the variable data changes? I can always put in a width specification into the gui, add, text line, and make it always longer than needs to be. but can this length be dependent on the variable data length? I know I can use 'guicontrol, move,... and put in a width #, but i'd prefer to have that width change with the width of the variable.

Code: Select all

Link = n/a

Gui, Add, Button, gFile_Link, File_Link
Gui, Add, Text, w100 vLink, % Link

Gui, Show, w250 h220, QuickAdd

return

File_Link:
msgbox, %Link%
FileSelectFile, Link
msgbox, %Link%
GuiControl,, Link, %Link%
msgbox, %Link%
return

exitapp

Re: Problem with GUI Control

Posted: 10 Jan 2018, 11:43
by A_AhkUser
Hi sttrebo,

You can for example use StrLen function in order to set the width of the control depending on the length of the input.

Code: Select all

Gui, Add, Button, Section gsubroutine, &File_Link
Gui, Add, Edit, ys+1 vtextControl +ReadOnly, n/a ; 'vtextControl' associates the variable 'textControl' with the control
Gui, Show, AutoSize, QuickAdd
return ; end of the auto-execute part of the script

subroutine: ;  named subroutine
FileSelectFile, selectedFile ; give relevant name to your variables
if not (ErrorLevel) { ;  if the user did not dismissed the dialog without selecting a file...
	link := StrReplace(selectedFile, A_Space, "%20") ; use functions instead; StrReplace returns the result of the replacement process(using expressions strings are enclosed in quotes)
	GuiControl,, textControl, % link
	GuiControl, Move, textControl, % "w" . StrLen(link)*5 ; set the width of the control depending on the length of the input (using expressions strings are enclosed in quotes)
	Gui, Show, AutoSize Center ; resize an center the GUI
}
return ; end of the subroutine

Hope this helps.

Re: Problem with GUI Control

Posted: 10 Jan 2018, 11:51
by sttrebo
very nice, thanks for the help all. i really appreciate all of the comments and assistance.