有办法在AutoHotKey源代码中进行换行吗?我的代码越来越长超过80个字符,我想把它们整齐地分开。我知道我们可以在其他语言中这样做,例如下面的VBA:
http://www.excelforum.com/excel-programming-vba-macros/564301-how-do-i-break-vba-code-into-two-or-more-lines.html
If Day(Date) > 10 _
And Hour(Time) > 20 Then _
MsgBox "It is after the tenth " & _
"and it is evening"在AutoHotKey中有中断代码行吗?我使用的是AutoHotKey的旧版本,Ver1.0.47.06
发布于 2014-11-27 07:18:11
文档中有一个将长线分割成一系列较短的线部分:
为了提高可读性和可维护性,可以将长行划分为一组较小的行。这并不会降低脚本的执行速度,因为这些行在脚本启动时就被合并到内存中。 方法#1:以" and“、”或“为开头的行,用逗号或句号自动与其正上方的行合并(在v1.0.46+中,除++和--外,所有其他表达式运算符也是如此。)在下面的示例中,第二行被追加到第一行,因为它以逗号开头:
FileAppend, This is the text to append.`n ; A comment is allowed here.
, %A_ProgramFiles%\SomeApplication\LogFile.txt ; Comment.类似地,以下行将合并为一行,因为最后两行以"and“或”or“开头:
if (Color = "Red" or Color = "Green" or Color = "Blue" ; Comment.
or Color = "Black" or Color = "Gray" or Color = "White") ; Comment.
and ProductIsAvailableInColor(Product, Color) ; Comment. 三元算子也是一个很好的候选:
ProductIsAvailable := (Color = "Red")
? false ; We don't have any red products, so don't bother calling the function.
: ProductIsAvailableInColor(Product, Color)虽然上面示例中使用的缩进是可选的,但它可以通过指示哪些行属于它们上面的行来提高清晰度。此外,没有必要为以" and“和”OR“开头的行添加额外的空格;程序会自动这样做。最后,可以在上述示例中的任何行之间或后面添加空行或注释。 方法2:该方法应该用于合并大量行,或者当这些行不适合方法1时。虽然该方法对于自动替换热字符串特别有用,但它也可以与任何命令或表达式一起使用。例如:
; EXAMPLE #1:
Var =
(
Line 1 of the text.
Line 2 of the text. By default, a line feed (`n) is present between lines.
)
; EXAMPLE #2:
FileAppend, ; The comma is required in this case.
(
A line of text.
By default, the hard carriage return (Enter) between the previous line and this one will be written to the file as a linefeed (`n).
By default, the tab to the left of this line will also be written to the file (the same is true for spaces).
By default, variable references such as %Var% are resolved to the variable's contents.
), C:\My File.txt在上面的例子中,一系列的线在顶部和底部被一对括号所包围。这就是所谓的延续部分。注意,底线包含FileAppend在结束括号之后的最后一个参数。此实践是可选的;它是在这种情况下完成的,因此逗号将被视为参数分隔符,而不是文字逗号。
有关更多细节,请阅读文档链接。
因此,您的示例可以重写如下:
If Day(Date) > 10
And Hour(Time) > 20 Then
MsgBox
(
It is after the tenth
and it is evening
)发布于 2014-11-26 20:25:48
我不知道这样做的一般方法,但似乎你可以用一个操作符来打破一条线,开始剩下的折线(例如,下一条真正的线)。只要第二行(以及适用的第三行、第四行等)以(可选的空格加)操作员开始,AHK将把整件事情当作一行。
例如:
hello := "Hello, "
. "world!"
MsgBox %hello%在第二行的逻辑开始处,级联操作符.的存在使AHK将这两行视为一行。
(我还试着离开操作符和第一行的末尾,然后用一个双引号字符串开始第二行;这是行不通的。)
https://stackoverflow.com/questions/27157174
复制相似问题