Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 07, 2016, 06:16:54 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: AHK Help  (Read 4676 times)

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 8,406
  • "In my dreams, I always do it right."
    • View Profile
    • Donate to Member
AHK Help
« on: January 21, 2010, 01:04:23 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 [Select]
  1. ; Variables
  2. _InputDirectory := "\\snlwebtool3\apps\TranslationRepository_test\"
  3. _OutputDirectory := "\\snlwebtool3\apps\TranslationRepository\Incoming"
  4. _PDFConverterPath := ProgramFiles . "\AnyBizSoft\PDFConverter\PDFConverter.exe"
  5.  
  6. ; Script Start
  7. 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,605
    • View Profile
    • Donate to Member
Re: AHK Help
« Reply #1 on: January 21, 2010, 04:50:27 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   

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,258
    • View Profile
    • Coding Snacks by Lanux128
    • Read more about this member.
    • Donate to Member
Re: AHK Help
« Reply #2 on: January 22, 2010, 08:11:47 AM »
what Target said but the line should be like this:

      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: 8,406
  • "In my dreams, I always do it right."
    • View Profile
    • Donate to Member
Re: AHK Help
« Reply #3 on: January 22, 2010, 10:37:32 AM »
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 [Select]
  1. MsgBox % "The value in the variable named Var is " . Var . "."  ; A period is used to concatenate (join) two strings.
  2. 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

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,667
    • View Profile
    • Donate to Member
Re: AHK Help
« Reply #4 on: January 22, 2010, 11:56:11 AM »
Code: AutoIt [Select]
  1. FileSelectFile % _SourceFileName, 3, _InputDirectory, "Select the file to be converted.", "Adobe PDF (*.pdf)" ; Your original
  2.              ; -----------------
  3.              ; This is the NAME of the variable to STORE the output path in.
  4.              ; You don't use "%" at all for this since you're simply
  5.              ; declaring the name of the variable.
  6.  
  7. FileSelectFile % _SourceFileName, 3, _InputDirectory, "Select the file to be converted.", "Adobe PDF (*.pdf)" ; Your original
  8.                                    ; ---------------
  9.                                    ; This is where you want to use the CONTENTS of a variable so this is where
  10.                                    ; you should use "% _InputDirectory" or "%_InputDirectory%" (minus quotes).
  11.  
  12. FileSelectFile _SourceFileName, 3, % _InputDirectory, "Select the file to be converted.", "Adobe PDF (*.pdf)" ; One correct way.
  13. 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, 11:57:47 AM by skwire »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 8,406
  • "In my dreams, I always do it right."
    • View Profile
    • Donate to Member
Re: AHK Help
« Reply #5 on: January 22, 2010, 04:40:57 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

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,667
    • View Profile
    • Donate to Member
Re: AHK Help
« Reply #6 on: January 22, 2010, 04:55:03 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 [Select]
  1. FileSelectFile, _SourceFileName, 3, % _InputDirectory, "Select the file to be converted.", "Adobe PDF (*.pdf)"
  2.             ; ^
  3.             ; |                    ^----------------^
  4.             ; |                            | Third "comma section" of the command.  Since we want to use the contents of
  5.             ; |                            | a variable, we can use either method, "% _InputDirectory" or %_InputDirectory%
  6.             ; |
  7.             ; |                 ^^
  8.             ; |                  | Second "comma section" of the command.
  9.             ; |
  10.             ; |^--------------^
  11.             ; |       | First "comma section" of the command.  No % used since we're declaring a variable name to store the outputted value.
  12.             ; |
  13.             ; |
  14.             ; | 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: 8,406
  • "In my dreams, I always do it right."
    • View Profile
    • Donate to Member
Re: AHK Help
« Reply #7 on: January 22, 2010, 04:58:11 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

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,667
    • View Profile
    • Donate to Member
Re: AHK Help
« Reply #8 on: January 22, 2010, 05:08:58 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 [Select]
  1. ; First method.
  2.  
  3. If ( a < b )
  4. {
  5.     c := 1
  6. }
  7. {
  8.     c := 2
  9. }
  10.  
  11. ; One-line shorthand method to accomplish the same as above.
  12. ; This uses a forced expression and a ternary operator.
  13.  
  14. % ( a < b ) ? ( c := 1 ) : ( c := 2 )

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 8,406
  • "In my dreams, I always do it right."
    • View Profile
    • Donate to Member
Re: AHK Help
« Reply #9 on: January 22, 2010, 09:25:07 PM »
Thanks for all of your help!

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,605
    • View Profile
    • Donate to Member
Re: AHK Help
« Reply #10 on: January 23, 2010, 03:03:21 AM »
the OutputVar (i.e. SourceFileName) need not be quoted..

DOH!! I should READ my posts before I send them...

cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,367
    • View Profile
    • Donate to Member
Re: AHK Help
« Reply #11 on: January 23, 2010, 12:26:17 PM »
DOH!! I should READ my posts before I send them...
Might as well try for one reader, at least!