这个问题在这篇文章的底部得到了回答。
我查看了 AHK 论坛中提出此问题的 6 个不同网页,以及另一个关于 SO 的网页:
...但他们都没有为我工作。我只是想从 StringSplit 函数中获取的字符串中减去一个数字。这是我的代码:
; Assign entry price variable.
StringSplit, prices, Window1Text, `n
MsgBox, Your entry price is %prices32%.
; Assign Stop Loss variable
SLPrice := %prices32% -= 0.10
MsgBox, Your SLPrice is %SLPrice%.
我在“ SLPrice := %prices32% -= 0.10 ”行上收到错误“以下变量名称包含非法字符”,然后我尝试:
; Assign entry price variable.
StringSplit, prices, Window1Text, `n
MsgBox, Your entry price is %prices32%.
; Assign Stop Loss variable
SLPrice = %prices32% - 0.10
MsgBox, Your SLPrice is %SLPrice%.
...我得到输出:
Your SLPrice is 7.450 - 0.10
所以它只是将公式显示为文本字符串,它实际上并不进行计算。
想法?谢谢!
更新要继续制定此解决方案,这里是我遇到问题的部分的完整代码,以及正在发生的事情的屏幕截图:
; Get the latest window text to parse values from it
WinGetText, Window1Text, ahk_class WindowsForms10.Window.8.app.0.f96fc5_r9_ad1
MsgBox, The text is: %Window1Text% ; Displays the window get text values
Sleep, 5
; Assign entry price variable.
StringSplit, prices, Window1Text, `n
MsgBox, Your entry price is %prices32%.
; Assign Stop Loss variable
SLPrice := prices32 - 0.10
MsgBox, Your SLPrice is %SLPrice%.
ANSWER感谢下面的贡献者,我们发现有一个“。” 从第一个 MsgBox 弄乱了 SLPrice 变量,所以我们更新了 SLPrice 变量以读取:
SLPrice := SubStr(Trim(prices32), 1, 5) - 0.10 ; to pull the left 5 characters
谢谢!
你走在正确的轨道上。但是,根据我的评论, note:=
表示包含变量表达式的表达式(因此没有周围的%
's):
; Assign entry price variable.
StringSplit, prices, Window1Text, `n
MsgBox, Your entry price is %prices32%.
; Assign Stop Loss variable
; Note, the 32 line also includes non printing characters
; so must be trimmed and then we take the left 5 characters
SLPrice := SubStr(Trim(prices32), 1, 5) - 0.10
MsgBox, Your SLPrice is %SLPrice%.
应该这样做。. .
请注意, usingsomething := %myvariable%
意味着读取命名变量的内容myvariable
并将这些内容用作变量名称。因此,如果myvariable
是“测试”,则您实际上是在说something := test
(某些东西最终等于test
变量的内容)。
嗯,
编辑如下,这是一个工作示例(但根据后面的评论,请参见下文):
Window1Text =
(
25
26
27
28
)
; Assign entry price variable.
StringSplit, prices, Window1Text, `n
MsgBox, Your entry price is %prices2%. ; using only 2nd line (26)
; Assign Stop Loss variable
SLPrice := prices2 - 0.10 ; again, changed to 2nd line
MsgBox, Your SLPrice is %SLPrice%. ; 25.900000
clipboard := SLPrice
哈,
进一步编辑:因为这真的很酷,并说明了几个概念,即它们与伪数组变量表达式的关系:
Window1Text =
(
25
26
27
28
)
; Assign entry price variable.
StringSplit, prices, Window1Text, `n ; (prices0 is the number of entries)
InputBox, num,, % "Pick an array number from 1 to " prices0 ; get the array number
; note the variable expression includes the num variable contents
MsgBox, % "Your entry price is " Trim(prices%num%) "." ; depends on array number
; Assign Stop Loss variable
SLPrice := Trim(prices%num%) - 0.10 ; uses the array number value
MsgBox, Your SLPrice is %SLPrice%. ; so depends on the array number
clipboard := SLPrice
正确的?
但请注意,这些测试人员很容易工作。来自 OP 的现实生活示例是复制文本,第 32 行包含由 处理的非打印字符,Trim(x)
并且只取 Left with 的前几个字符SubStr(x,1,5)
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句