possible to put variable in function? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

possible to put variable in function?

17 Oct 2021, 02:10

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
}
Rohwedder
Posts: 7625
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: possible to put variable in function?

17 Oct 2021, 02:14

Hallo,
try:

Code: Select all

RunOrActivate2(Drive ":\Dropbox\App Sync\Telegram\Telegram.exe", "ahk_exe Telegram.exe")
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: possible to put variable in function?

17 Oct 2021, 07:54

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")
Last edited by milkygirl90 on 17 Oct 2021, 07:58, edited 1 time in total.
ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: possible to put variable in function?

17 Oct 2021, 08:03

@milkygirl90 Seriously? 533 posts and you still don't know the basics?
Rohwedder
Posts: 7625
Joined: 04 Jun 2014, 08:33
Location: Germany

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

17 Oct 2021, 11:15

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")
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: possible to put variable in function?

17 Oct 2021, 17:26

@Rohwedder , you have been most helpful. appreciate it!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750, nacken012 and 219 guests