Page 1 of 1

possible to put variable in function?

Posted: 17 Oct 2021, 02:10
by milkygirl90

Code: Select all


Drives := "CDE"
Loop Parse, Drives
    if FileExist(A_LoopField ":\Dropbox"){
        Drive:=A_Loopfield
        break
        }
		OnClipboardChange("CleanLink")
		SetScrollLockState, AlwaysOff
		
#NumPad5::
RunOrActivate2("%Drive%:\Dropbox\App Sync\Telegram\Telegram.exe", "ahk_exe Telegram.exe") ; I can't seem to put %Drive% as a parameter here.

RunOrActivate2(Target, WinTitle = "")
{
global Drive
If WinExist("%WinTitle%")
WinActivate
Else
Run, %Target%
return
}

Re: possible to put variable in function?

Posted: 17 Oct 2021, 02:14
by Rohwedder
Hallo,
try:

Code: Select all

RunOrActivate2(Drive ":\Dropbox\App Sync\Telegram\Telegram.exe", "ahk_exe Telegram.exe")

Re: possible to put variable in function?

Posted: 17 Oct 2021, 07:54
by milkygirl90
ah thanks! what should the syntax look like if I'm inserting the default username instead?

Code: Select all

RunOrActivate2("C:\users\" .%A_USERNAME% . "\AppData\Roaming\Spotify\Spotify.exe", "ahk_exe Spotify.exe")

Re: possible to put variable in function?

Posted: 17 Oct 2021, 08:03
by ahk7
@milkygirl90 Seriously? 533 posts and you still don't know the basics?

Re: possible to put variable in function?  Topic is solved

Posted: 17 Oct 2021, 11:15
by Rohwedder

Code: Select all

RunOrActivate2("C:\users\" . A_USERNAME . "\AppData\Roaming\Spotify\Spotify.exe", "ahk_exe Spotify.exe")
or:

Code: Select all

RunOrActivate2("C:\users\" A_USERNAME "\AppData\Roaming\Spotify\Spotify.exe", "ahk_exe Spotify.exe")

Re: possible to put variable in function?

Posted: 17 Oct 2021, 17:26
by milkygirl90
@Rohwedder , you have been most helpful. appreciate it!