Variable Help in GUI

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Crysiz_Gaming
Posts: 11
Joined: 14 Nov 2022, 15:09
Contact:

Variable Help in GUI

Post by Crysiz_Gaming » 09 Jun 2023, 02:45

Code: Select all

var1 := "UrlDownloadToFile, %Link%, C:\Users\%A_Username%\AppData\Local\Temp\%FileName%"
var2 := "Run, C:\Users\%A_Username%\AppData\Local\Temp\%FileName%"


Start:
Msgbox %var1%
Msgbox %var2%
The script does NOT prompt the variables? any reason or how to fix?

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

Re: Variable Help in GUI

Post by boiler » 09 Jun 2023, 03:52

If you have each variable mentioned in those lines already defined (in addition to the built-in ones) and are trying to insert their values into those strings, then your expression syntax is not correct. Should be:

Code: Select all

var1 := "UrlDownloadToFile, " Link ", C:\Users\" A_Username "\AppData\Local\Temp\" FileName
var2 := "Run, C:\Users\" A_Username "\AppData\Local\Temp\" FileName

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Variable Help in GUI

Post by wetware05 » 09 Jun 2023, 04:37

Code: Select all

Filename:= "Arrays.jpg"
Link:= "https://en.wikipedia.org/wiki/File:Modern_AutoHotkey_Logo_(no_text).svg"
User:= A_Username ; Abbreviate a variable name to make it friendlier
Dir_temp:= "C:\Users\" User "\AppData\Local\Temp\"

var1 := "UrlDownloadToFile: " Link  " C:\Users\" A_Username "\AppData\Local\Temp\" FileName ;a command in a variable can only be saved as text
var2 := Dir_Temp FileName ; Chain two variables


Msgbox %var1%
Msgbox %var2%

Run, %var2% ; this line will not be fulfilled, because the graphic "var2" does not exist in the system temporary directory

UrlDownloadToFile, %Link%, html_page.svg ; will download the image linked to the "link" variable

Crysiz_Gaming
Posts: 11
Joined: 14 Nov 2022, 15:09
Contact:

Re: Variable Help in GUI

Post by Crysiz_Gaming » 10 Jun 2023, 05:46

Code: Select all

Gui, Add, Text, x12 y9 w320 h30 , Downloader
Gui, Add, Edit, x12 y59 w320 h30 vLink
Gui, Add, Edit, x12 y109 w320 h30 vFileName
Gui, Add, Text, x12 y39 w320 h20 , Direct Download Link:
Gui, Add, Text, x12 y89 w320 h20 , File Name
Gui, Add, Button, x12 y139 w320 h30 gStart, Build
Gui, Show, x492 y191 h186 w349, Downloader
Return
Gui, Submit
var1 := "UrlDownloadToFile, %Link%, C:\Users\%A_Username%\AppData\Local\Temp\%FileName%"
var2 := "Run, C:\Users\%A_Username%\AppData\Local\Temp\%FileName%"


Start:
Msgbox %var1%
Msgbox %var2%
Sleep, 1000
FileAppend, %var1%, %A_WorkingDir%\build.tmp
Sleep, 1000
FileAppend, %var2%, build.tmp
Sleep, 1000
FileMove, %A_WorkingDir%\build.tmp, %A_WorkingDir%\build.ahk
Sleep, 1000
Msgbox, Done!
Return

GuiClose:
ExitApp

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

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

Re: Variable Help in GUI

Post by boiler » 10 Jun 2023, 05:53

Your three lines after the Return line will never run. You must want them to execute when the Start subroutine is executed, so move them into there.

Not sure why you didn't incorporate anything that was shown to you or if you even have a question. You just posted some code and didn't ask anything or point out what wasn't working as you expected.

Crysiz_Gaming
Posts: 11
Joined: 14 Nov 2022, 15:09
Contact:

Re: Variable Help in GUI

Post by Crysiz_Gaming » 10 Jun 2023, 06:14

Thank you boiler. i got it working as expected. sorry for not pointing out the error. ty :bravo:

Post Reply

Return to “Ask for Help (v1)”