DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: AHK Help  (Read 13,420 times)

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 11,205
    • Participated in NANY Challenge Fourteen Times
    • Coding Snacks
    • Writer
    • Hardware Hacker
AHK Help
« on: January 21, 2010, 07:04 PM »
I need a little utility program to automate use of some third party software, so I thought this was the perfect time to learn a little AutoHotKey.  But, I'm running into a bit of a problem.  Can someone tell me where I'm going wrong with the following snippet?  Using the latest AHK downloaded from the AHK site.

Code: (autoit)
; Variables
_InputDirectory := "\\snlwebtool3\apps\TranslationRepository_test\"
_OutputDirectory := "\\snlwebtool3\apps\TranslationRepository\Incoming"
_PDFConverterPath := ProgramFiles . "\AnyBizSoft\PDFConverter\PDFConverter.exe"

; Script Start
FileSelectFile % _SourceFileName, 3, _InputDirectory, "Select the file to be converted.", "Adobe PDF (*.pdf)"

I get the following error:
C:\Dev\.NET20\Document System\SNL.DocumentTranslationService\Scripts\PDFConverter.ahk (21) : ==> This parameter contains a variable name missing its ending percent sign.
    Specifically: % _SourceFileName

It works if I take the % out, but then it's not using the values of the variables, but the variable names.

Thoughts?

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,840
    • Coding Snacks
Re: AHK Help
« Reply #1 on: January 21, 2010, 10:50 PM »
Wraith

i think the correct syntax is

    FileSelectFile, %_SourceFileName%, 3,%_InputDirectory%, Select the file to be converted, Adobe PDF (*.pdf)

you were getting an error because you 'opened' a variable with your first % but didn't close it (at least that's how AHK see's it)

Also note that it's not necessary (in this case) to enclose your text values 
Alcohol is photoshop, bottled
Askhole - someone who ask for advice, then ignores it
"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • Coding Snacks
    • Volunteers/Staff
    • Gathering Badge
    • Participated in NANY Challenge Once
    • Linux User
Re: AHK Help
« Reply #2 on: January 22, 2010, 02:11 PM »
what Target said but the line should be like this:

Code
      FileSelectFile _SourceFileName, 3, %_InputDirectory%, "Select the file to be converted.", "Adobe PDF (*.pdf)"

the OutputVar (i.e. SourceFileName) need not be quoted..

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 11,205
    • Participated in NANY Challenge Fourteen Times
    • Coding Snacks
    • Writer
    • Hardware Hacker
Re: AHK Help
« Reply #3 on: January 22, 2010, 04:37 PM »
I was trying to use expression format, i.e. (from the documentation)

Quote
By contrast, the expression method omits the percent signs around variable names, but encloses literal strings in quotes. Thus, the following are the expression equivalents of the previous examples:

Code: (autoit)
MsgBox % "The value in the variable named Var is " . Var . "."  ; A period is used to concatenate (join) two strings.
CopyOfVar := Var

I already changed it to the manner which you gave after seeing it would work, and getting around my need for expressions in that case.  But why didn't using the expression method work?

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: AHK Help
« Reply #4 on: January 22, 2010, 05:56 PM »
Code: (autoit)
FileSelectFile % _SourceFileName, 3, _InputDirectory, "Select the file to be converted.", "Adobe PDF (*.pdf)" ; Your original
             ; -----------------
             ; This is the NAME of the variable to STORE the output path in.
             ; You don't use "%" at all for this since you're simply
             ; declaring the name of the variable.

FileSelectFile % _SourceFileName, 3, _InputDirectory, "Select the file to be converted.", "Adobe PDF (*.pdf)" ; Your original
                                   ; ---------------
                                   ; This is where you want to use the CONTENTS of a variable so this is where
                                   ; you should use "% _InputDirectory" or "%_InputDirectory%" (minus quotes).

FileSelectFile _SourceFileName, 3, % _InputDirectory, "Select the file to be converted.", "Adobe PDF (*.pdf)" ; One correct way.
FileSelectFile _SourceFileName, 3, %_InputDirectory%, "Select the file to be converted.", "Adobe PDF (*.pdf)" ; Another correct way. 
                                       
Does that help to explain things?
« Last Edit: January 22, 2010, 05:57 PM by skwire »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 11,205
    • Participated in NANY Challenge Fourteen Times
    • Coding Snacks
    • Writer
    • Hardware Hacker
Re: AHK Help
« Reply #5 on: January 22, 2010, 10:40 PM »
Maybe... so the percent sign-space combo to change the method from traditional to expression based goes in front of the first variable that would be affected?  Or all variables?  Or am I missing something still?  I was under the impression that to change the method call to expression based, you added the percent sign-space combo after the method call name (which is apparently wrong), but I'm still not 100% sure I understand where it is to be placed...

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: AHK Help
« Reply #6 on: January 22, 2010, 10:55 PM »
I agree that it's rather confusing at first but easy (and flexible) once you get the hang of it.  Yes, the "% " combo does force an expression but only for that "comma section" of the command you're using.  In other words, each "comma section" of a command is separate from the others.  Example:

Code: (autoit)
FileSelectFile, _SourceFileName, 3, % _InputDirectory, "Select the file to be converted.", "Adobe PDF (*.pdf)"
            ; ^
            ; |                    ^----------------^
            ; |                            | Third "comma section" of the command.  Since we want to use the contents of 
            ; |                            | a variable, we can use either method, "% _InputDirectory" or %_InputDirectory%
            ; |
            ; |                 ^^
            ; |                  | Second "comma section" of the command.
            ; |
            ; |^--------------^
            ; |       | First "comma section" of the command.  No % used since we're declaring a variable name to store the outputted value.
            ; |
            ; |
            ; | Note that comma I put in.  It doesn't NEED to be there but it's a good habit to get into.

Clear as mud now?   :D

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 11,205
    • Participated in NANY Challenge Fourteen Times
    • Coding Snacks
    • Writer
    • Hardware Hacker
Re: AHK Help
« Reply #7 on: January 22, 2010, 10:58 PM »
Yes!  I get it now... thanks!  The examples aren't as clear as what you've shown (especially since they omit the comma after the method name). :)

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: AHK Help
« Reply #8 on: January 22, 2010, 11:08 PM »
Great.  Also, you can use the "% " to force an expression on a line by itself.  This can be very handy when you want to use a ternary operator. 

Example:

Code: (autoit)
; First method.

If ( a < b )
{
    c := 1
}
Else
{
    c := 2
}

; One-line shorthand method to accomplish the same as above.
; This uses a forced expression and a ternary operator.

% ( a < b ) ? ( c := 1 ) : ( c := 2 )

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 11,205
    • Participated in NANY Challenge Fourteen Times
    • Coding Snacks
    • Writer
    • Hardware Hacker
Re: AHK Help
« Reply #9 on: January 23, 2010, 03:25 AM »
Thanks for all of your help!

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,840
    • Coding Snacks
Re: AHK Help
« Reply #10 on: January 23, 2010, 09:03 AM »
the OutputVar (i.e. SourceFileName) need not be quoted..

DOH!! I should READ my posts before I send them...
Alcohol is photoshop, bottled
Askhole - someone who ask for advice, then ignores it
"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler

cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,776
    • Cody Award
    • Official Forum Clown
    • rotten turkey sandwich - Rotten Turkey Sandwich
Re: AHK Help
« Reply #11 on: January 23, 2010, 06:26 PM »
DOH!! I should READ my posts before I send them...
Might as well try for one reader, at least!
Chris

Original address: https://www.donationcoder.com/forum/index.php?topic=21448.0