Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Why doesn't StringLeft work for me?


  • Please log in to reply
2 replies to this topic
joelr
  • Members
  • 6 posts
  • Last active: Apr 06 2004 05:11 AM
  • Joined: 15 Mar 2004
Why does this line:

StringLeft, title, clipboard, 1

throw this error: "This parameter of this line doesn't resolve to a non-negative numeric integer as required.

Info: 1;43-1" ?

joelr
  • Members
  • 6 posts
  • Last active: Apr 06 2004 05:11 AM
  • Joined: 15 Mar 2004
Ok, so I actually trimmed off the last part of the code line which was ";%var%" and %var% was 43-1, which I thought would be a number, but I guess AHK things it's a string... I also thought that anything after a semicolon was considered a comment. Is this not true?

So the only way to subtract in AHK is via the "-=" operator?

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Yes, everything stored in a variable is stored as a string and you're right that AHK cannot evaluate expressions contained in parameters; you must first perform the subtraction as a calculation on a separate line, e.g. Var -= 1

Also, in order for a semicolon to be a comment, it must have at least one tab or space to it's left. For example:

StringLeft, title, clipboard, 1 ; This is a comment.
StringLeft, title, clipboard, 1; This is not. (it is part of the parameter)

If you ever want a literal semicolon with a space or tab to its left, you can escape it:

StringLeft, title, clipboard, 1 `; This is not a comment since the semicolon is escaped.