Jump to content

Recommended Posts

Posted (edited)
While Number($LowVac) > Number(ControlGetText("Window", "", 2865)) And Number($HiVac) < Number(ControlGetText("Window", "", 2865))
      Sleep (1000)
      $BadPressTime = $BadPressTime +1
      GUICtrlSetData (4, $BadPressTime)
      GUICtrlSetData (6, "Please wait.")
      GetPress()
   WEnd

I finally figured out what is going on with my script and my programming skills but I am not sure how to overcome this.  Could someone please help?

I have a value in a GUI that I need to monitor.  If that value is within +- 10% of a target then I would like to start counting.  Once that value has been met for 5 seconds then I want to continue.  The value I am reading is a vacuum level.  If I write my script with exact numbers I don't have a problem because I can force a numeric comparison with == or <>.  But whenever I use > or < then autoit assumes my value is text and it fails.  So how can I force the comparison in a > or < situation?

I tried using Number as in the example but it failed.  Please help!

 

 

Edited by rawkhopper
Posted
41 minutes ago, rawkhopper said:

If I write my script with exact numbers I don't have a problem because I can force a numeric comparison with ==

It doesn't make sense, since the == operator is used only to make a case-sensitive comparsion between strings.

By the way, we can't run your script, so, post a practical example :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Posted

According to https://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm < or > can be compared lexicographically.  But I want it to be numerically.  How can you force it?  

 

The script I wrote will will not work independently of the window I am working with.  It would take a lot of effort to try to remove the dependencies on the program I am trying to read.

 

Can someone tell me how to force autoit to not compare a greater than or less than statement lexigraphically?

Posted

Your logic is flawed.  If I understand your context correctly, the value you're reading comes from the control id 2865 and you want to count 5 s starting from when the read value is within $LowVac and $HiVac.  Is that a correct description?

Your code tests $value < $low AND $value > $high which isn't possible, provided $low <= $high.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

you  need some debugging methods  (like consolewrite ) to track your code for exp :-
 

While 1
    $GUi_Value=ControlGetText("Window", "", 2865)

    $LowVac=number($LowVac)
    $HiVac=number($HiVac)
    $GUi_Value=number($GUi_Value)

    ConsoleWrite("variable LowVac = "&$LowVac&@CRLF)       ;For debug
    ConsoleWrite("variable HiVac = "&$HiVac&@CRLF)         ;for debug
    ConsoleWrite("variable GUi_Value = "&$GUi_Value&@CRLF) ;for debug

    if not ($LowVac > $GUi_Value and $HiVac < $GUi_Value) Then ExitLoop

      Sleep (1000)
      $BadPressTime = $BadPressTime +1
      GUICtrlSetData (4, $BadPressTime)
      GUICtrlSetData (6, "Please wait.")
      GetPress()
   WEnd



 

Posted (edited)

I believe the code you need is along this line:

Local $AllowedTime = 5 * 60 * 1000      ; 5 minute window to permit stable measure
Local $dt = 250                         ; 250 ms between acquisitions
Local $tMeasure                         ; stability duration timer
Local $tTotal = TimerInit()             ; allowable window timer

While 1
    If TimerDiff($tTotal) > $AllowedTime Then
        MsgBox(0, "Fatal", "Required vacuum level never reached")
        Exit                            ; terminate more or less gracefully (or take corrective action)
    EndIf
    While Not VacInRange() AND TimerDiff($tTotal) < $AllowedTime
        Sleep($dt)
    WEnd
    $tMeasure = TimerInit()
    Do
        Sleep($dt)
        If Not VacInRange() Then ExitLoop
    Until TimerDiff($tMeasure) >= 5000  ; pressure must remain within acceptable range for 5 s
    If TimerDiff($tMeasure) >= 5000 Then ExitLoop
WEnd

; more processing
; ...

Func VacInRange()
    Local $Vac = Number(ControlGetText("Window", "", 2865))
    Return $Vac >= $LowVac And $Vac =< $HiVac
EndFunc

 

Edited by jchd
Fix typos & thinkos & use better exit cond.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted (edited)

OK I feel like an idiot now.  I worked hard all day focusing on the logic.  I was sure I had it all right. So then I started to look for other reasons it wasn't working and discovered Number() and so I thought for sure that would fix it... it did but between me fixing the logic and finding Number() I screwed up my logic and didn't realize I had fixed it because I got the same result but this time due to the logic.

Stupid copy and paste error.

Thanks for the help guys!  It didn't dawn on me that I had copied and pasted the logic from another portion of the script and thereby screwing up the logic.

 

Edited by rawkhopper

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...