Autohotkey_L数字比较问题

时间:2013-02-12 04:33:26

标签: object comparison ocr autohotkey numeric

我有一个循环8个数字的脚本,跳过负数并返回最大值,如下所示:

biggest = 0
entry = 0
loop, 8
    {
    ; MsgBox %A_Index%
    if NegativeReadings%A_Index% not contains - ;filter out readings that are negative
        {
        ; MsgBox % AttributeReadings%A_Index%
        MsgBox %biggest%
        ; MsgBox % AttributeReadings%A_Index%
        if (AttributeReadings[A_Index] > biggest)
            {
            biggest := AttributeReadings[A_Index]
            entry = %A_Index%
            }
        }
    }
MsgBox %entry%

当我用100,100,150,100,50,100,110,75输入一些样本图像时,OCR正确返回对象数组结果,但数字比较失败

我得到MsgBox%最大%= 0,100,100,150, 150,50 ,50,50 => %entry%= 8

在(50> 150)之间发生了错误我在处理ahk中的数据类型方面没什么线索,欢迎任何帮助

1 个答案:

答案 0 :(得分:0)

好吧,我今晚在第二次拍摄时想到了,OCR正在返回一个带有尾随空格的字符串,所以它导致管理员提到的字母比较。

用regexp修剪它现在它工作得很好 以下是可能遇到此类似问题的任何人的代码段

#SingleInstance force
#Include OCR.ahk

; sleep 5000
OCR()
; global
    {
    AttributeReadings := Object()
    loop, 8
        {
        NegativeReadings%A_Index% := GetOCR(730, (136 + (17 * (A_Index - 1))), 35, 17)
        AttributeReadings[A_Index] := GetOCR(730, (136 + (17 * (A_Index - 1))), 35, 17, "numeric")
        ; MsgBox % AttributeReadings%A_Index%
        }
    biggest = 0
    entry = 0
    i = 0
    loop, 8
        {
        ; MsgBox %A_Index%
        if NegativeReadings%A_Index% not contains - ;filter out readings that are negative
            {
            ; MsgBox % AttributeReadings%A_Index%
            ; length := StrLen(biggest)
            ; MsgBox %biggest%, %length%
            number := RegExReplace(AttributeReadings[A_Index], "([space])?", "")
            MsgBox %number%
            ; MsgBox % AttributeReadings%A_Index%
            if (number > biggest)
                {
                biggest := number
                entry := i
                }
            }
            i++
        }
    MsgBox %entry%
    }
End::
OCR()
return

上面的代码基本上是从图像中读取一个数字列表并返回第一个非负数。至于负过滤部分,它是在OCR中完成的,因为我的测试用例没问题,你可能想根据你正在使用的图像修改它