problem with variable not being recognized in a line.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bapiman
Posts: 9
Joined: 20 Jan 2017, 08:10

problem with variable not being recognized in a line.

Post by bapiman » 17 May 2022, 17:26

Hi there. Hoping someone can advise.

I have a variable that equals a textual expression (ie c:\temp)
So in the script I would have input at the start var1 = c:\temp

Anywhere in the script where I input %var1% it correctly substitutes with c:\temp apart from one line which refuses to work:

Code: Select all

FileAppend, %Clipboard%, %var1%\file.tmp
Whatever I try %var1% seems to refuse to substitute to c:\temp (file.tmp does NOT get created in c:\temp)

However...if I try the following it works:

Code: Select all

FileAppend, %Clipboard%, c:temp\file.tmp
Appreciate your help

User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: problem with variable not being recognized in a line.

Post by mikeyww » 17 May 2022, 17:29

Code: Select all

var1 = c:\temp
FileCreateDir, %var1%
FileAppend, %Clipboard%, %var1%\file.tmp

User avatar
JoeWinograd
Posts: 2179
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: problem with variable not being recognized in a line.

Post by JoeWinograd » 17 May 2022, 18:34

Hi @bapiman,

If this works:

Code: Select all

FileAppend, %Clipboard%, c:temp\file.tmp
But this does not work:

Code: Select all

FileAppend, %Clipboard%, %var1%\file.tmp
It means that var1 does not contain c:temp. A simple MsgBox % var1 before the FileAppend will show you what's in var1.

Btw, although c:temp works, it's better practice to include the backslash after the drive, i.e., c:\temp. Regards, Joe

User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: problem with variable not being recognized in a line.

Post by mikeyww » 17 May 2022, 19:55

Those are great points. I think that you are also asking us to debug a script that we cannot see! Posting your script is always an option.

Post Reply

Return to “Ask for Help (v1)”