EAHuaroto Posted August 12, 2022 Share Posted August 12, 2022 (edited) Hi experts, I'm new in scripting =( I'm trying to find the way of how to make my system beep when I scan an item in my retail VB6 POS software. I took the "TOTAL Textbox" Control which is part of the main interface as the variable element. I created these simple codes but the problem is that sometimes it does work and sometimes it doesn't, so that'd be kind of confusing. I'd appreciate your help --------------------------------------------------------------------------------------------------------------- Local $i = 0 Do If WinActive("[Title:Caja]") Then ; Check if POS Window is currently active. $sText = ControlGetText("Caja","","ThunderRT6TextBox21"); Get data from "TOTAL Textbox" Sleep(1) $sText2 = ControlGetText("Caja","","ThunderRT6TextBox21");Get data from "TOTAL Texbox" to be compared If $sText <> $sText2 Then ;Beep if "TOTAL Textbox" value changes Beep(650, 200) ;Beep sound EndIf EndIf $i = $i + 1 Until $i = 10000000000 Exit Edited August 15, 2022 by EAHuaroto Link to comment Share on other sites More sharing options...
Zedna Posted August 12, 2022 Share Posted August 12, 2022 $sTextOld = '' While True If WinActive("[Title:Caja]") Then ; Check if POS Window is currently active. $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21"); Get data from "TOTAL Textbox" If $sText <> $sTextOld Then ;Beep if "TOTAL Textbox" value changes Beep(650, 200) ;Beep sound $sTextOld = $sText EndIf EndIf Sleep(250) WEnd EAHuaroto 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
EAHuaroto Posted August 14, 2022 Author Share Posted August 14, 2022 Works fine but, is it possible that, when Textbox shows "0" this will not sound? Link to comment Share on other sites More sharing options...
OJBakker Posted August 14, 2022 Share Posted August 14, 2022 try with $sTextOld = '0' or add an extra check to the if-statements surrounding the beep. Link to comment Share on other sites More sharing options...
EAHuaroto Posted August 14, 2022 Author Share Posted August 14, 2022 5 hours ago, OJBakker said: try with $sTextOld = '0' or add an extra check to the if-statements surrounding the beep. That's exactly what I thought from the first moment but nothing, It still sounds when the textbox shows "0". I guess the reason has to do with the "Comparison Operator" Ref: $value changed from ' ' to '0' $sTextOld = '0' While True If WinActive("[Title:Caja]") Then ; Check if POS Window is currently active. $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21"); Get data from "TOTAL Textbox" If $sText <> $sTextOld Then ; Beep if "TOTAL Textbox" value changes Beep(650, 200) ;Beep sound $sTextOld = $sText EndIf EndIf Sleep(250) WEnd Link to comment Share on other sites More sharing options...
OJBakker Posted August 14, 2022 Share Posted August 14, 2022 Check the value of @error after ControlGetText. If there is an error the returnvalue in $sText will be an empty string and your code will beep. Link to comment Share on other sites More sharing options...
Musashi Posted August 14, 2022 Share Posted August 14, 2022 1 hour ago, EAHuaroto said: I guess the reason has to do with the "Comparison Operator" To check the values of $sTextOld and $sText before comparing, include some ConsoleWrite's. The <> operator itself should not be the problem. ; [...] $sTextOld = '' While True If WinActive("[Title:Caja]") Then ; Check if POS Window is currently active. $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21"); Get data from "TOTAL Textbox" ConsoleWrite("-------------------------------------------------" & @CRLF) ConsoleWrite("TextOld = " & $sTextOld & @CRLF) ConsoleWrite("Text = " & $sText & @CRLF) If $sText <> $sTextOld Then ; Beep if "TOTAL Textbox" value changes Beep(650, 200) ;Beep sound $sTextOld = $sText ConsoleWrite("Beep" & @CRLF) Else ConsoleWrite("no Beep" & @CRLF) EndIf EndIf Sleep(250) WEnd EAHuaroto 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Werty Posted August 14, 2022 Share Posted August 14, 2022 Check for both, if it's other than 0 And other than old then beep. $sTextOld = '' While True If WinActive("[Title:Caja]") Then ; Check if POS Window is currently active. $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21"); Get data from "TOTAL Textbox" If $sText <> "0" And $sText <> $sTextOld Then ;Beep if "TOTAL Textbox" value changes Beep(650, 200) ;Beep sound $sTextOld = $sText EndIf EndIf Sleep(250) WEnd Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
Zedna Posted August 15, 2022 Share Posted August 15, 2022 Is it 0 or 0,00? Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
EAHuaroto Posted August 15, 2022 Author Share Posted August 15, 2022 6 minutes ago, Zedna said: Is it 0 or 0,00? It is 0,00Є the sale starting point Link to comment Share on other sites More sharing options...
EAHuaroto Posted August 15, 2022 Author Share Posted August 15, 2022 14 hours ago, Musashi said: To check the values of $sTextOld and $sText before comparing, include some ConsoleWrite's. The <> operator itself should not be the problem. ; [...] $sTextOld = '' While True If WinActive("[Title:Caja]") Then ; Check if POS Window is currently active. $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21"); Get data from "TOTAL Textbox" ConsoleWrite("-------------------------------------------------" & @CRLF) ConsoleWrite("TextOld = " & $sTextOld & @CRLF) ConsoleWrite("Text = " & $sText & @CRLF) If $sText <> $sTextOld Then ; Beep if "TOTAL Textbox" value changes Beep(650, 200) ;Beep sound $sTextOld = $sText ConsoleWrite("Beep" & @CRLF) Else ConsoleWrite("no Beep" & @CRLF) EndIf EndIf Sleep(250) WEnd I tried this new method using ConsoleWrite but still, the result is the same, the beep sound gets activated even when the Textbox shows "0". Link to comment Share on other sites More sharing options...
Developers Jos Posted August 15, 2022 Developers Share Posted August 15, 2022 Please change those lines to: ConsoleWrite("-------------------------------------------------" & @CRLF) ConsoleWrite("TextOld =" & $sTextOld & "|" & @CRLF) ConsoleWrite("Text =" & $sText & "|" & @CRLF) .. and show us the output text when it still beeps while not changed. EAHuaroto 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Zedna Posted August 15, 2022 Share Posted August 15, 2022 Try this: $sTextOld = '' While True If WinActive("[Title:Caja]") Then ; Check if POS Window is currently active. $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21"); Get data from "TOTAL Textbox" If $sText <> $sTextOld Then ;Beep if "TOTAL Textbox" value changes If Number($sText) <> 0 Then Beep(650, 200) ;Beep sound (not when 0 / 0,00) $sTextOld = $sText EndIf EndIf Sleep(250) WEnd Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
EAHuaroto Posted August 15, 2022 Author Share Posted August 15, 2022 28 minutes ago, Zedna said: Try this: $sTextOld = '' While True If WinActive("[Title:Caja]") Then ; Check if POS Window is currently active. $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21"); Get data from "TOTAL Textbox" If $sText <> $sTextOld Then ;Beep if "TOTAL Textbox" value changes If Number($sText) <> 0 Then Beep(650, 200) ;Beep sound (not when 0 / 0,00) $sTextOld = $sText EndIf EndIf Sleep(250) WEnd Ok, this makes my system stop beeping when the textbox shows "0" but it looks like a little problem has arisen. When I start a new sale, I scan an item, the system doesn't sound, not until the "Total textbox" value reaches "1,00". Looks like It is not considering the decimals "0,01" . So, if I scan an item lower priced than "1,00", the system simply will not sound. Link to comment Share on other sites More sharing options...
OJBakker Posted August 15, 2022 Share Posted August 15, 2022 See the description of function Number(). Default this function returns an integer. You can add a second parameter so this function will also return decimals. Link to comment Share on other sites More sharing options...
Musashi Posted August 15, 2022 Share Posted August 15, 2022 (edited) 28 minutes ago, OJBakker said: See the description of function Number(). Default this function returns an integer. You can add a second parameter so this function will also return decimals. The Number function returns a floating point number even without any additional flags (default). The only thing that must be followed is the valid notation for the separator, i.e. dot instead of comma. Example : #include <AutoItConstants.au3> Local $sText $sText = "0,01" ConsoleWrite($sText & @CRLF) ConsoleWrite("-> " & Number($sText) & @CRLF) $sText = "0.01" ConsoleWrite($sText & @CRLF) ConsoleWrite("-> " & Number($sText) & @CRLF) ; replace , with . $sText = "0,01" ConsoleWrite($sText & @CRLF) ConsoleWrite("Replace , with . :" & @CRLF) ConsoleWrite("-> " & Number(StringReplace($sText, ',', '.')) & @CRLF) @EAHuaroto : Use @Zedna 's example with the following modification : ; [...] $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21"); Get data from "TOTAL Textbox" $sText = StringReplace(StringStripWS($sText, 8), ',', '.') Edited August 15, 2022 by Musashi EAHuaroto 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
OJBakker Posted August 15, 2022 Share Posted August 15, 2022 The flag parameter is described in the manual as: $NUMBER_AUTO (0) = (default) the result is auto-sized integer. See remarks. The remarks in the manual describe it differently. So it seems the description of the flag parameter should not use the word integer. Link to comment Share on other sites More sharing options...
EAHuaroto Posted August 15, 2022 Author Share Posted August 15, 2022 You made it guys! Thank you all! specially to @Zedna who has provided, in my opinion, the base of the solution. So here is the code that is actually working perfectly on my system : $sTextOld = '' While True If WinActive("[Title:Caja]") Then ;Check if POS Window is currently active. $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21") ;Get data from "TOTAL Textbox" $sText = StringReplace(StringStripWS($sText, 8), ',', '.') If $sText <> $sTextOld Then ;Beep if "TOTAL Textbox" value changes If Number($sText) <> 0 Then Beep(660, 300) ;Beep sound (not when 0 / 0,00) $sTextOld = $sText EndIf EndIf Sleep(0) WEnd Link to comment Share on other sites More sharing options...
Solution Zedna Posted August 16, 2022 Solution Share Posted August 16, 2022 (edited) Here is little optimized version: 1) In StringReplace use CaseSense=1 -> faster 2) StringReplace+StringStripWS do only if neccessary (just before Beep) -> less CPU load in main loop $sTextOld = '' While True If WinActive("[Title:Caja]") Then ;Check if POS Window is currently active. $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21") ;Get data from "TOTAL Textbox" If $sText <> $sTextOld Then ;Beep if "TOTAL Textbox" value changes If Number(StringReplace(StringStripWS($sText, 8), ',', '.',1)) <> 0 Then Beep(660, 300) ;Beep sound (not when 0 / 0,00) $sTextOld = $sText EndIf EndIf Sleep(0) WEnd Edited August 16, 2022 by Zedna EAHuaroto 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
EAHuaroto Posted August 16, 2022 Author Share Posted August 16, 2022 (edited) 6 hours ago, Zedna said: Here is little optimized version: 1) In StringReplace use CaseSense=1 -> faster 2) StringReplace+StringStripWS do only if neccessary (just before Beep) -> less CPU load in main loop $sTextOld = '' While True If WinActive("[Title:Caja]") Then ;Check if POS Window is currently active. $sText = ControlGetText("Caja", "", "ThunderRT6TextBox21") ;Get data from "TOTAL Textbox" If $sText <> $sTextOld Then ;Beep if "TOTAL Textbox" value changes If Number(StringReplace(StringStripWS($sText, 8), ',', '.',1)) <> 0 Then Beep(660, 300) ;Beep sound (not when 0 / 0,00) $sTextOld = $sText EndIf EndIf Sleep(0) WEnd Great, thanks! …By the way, using this code, I mean not creating a new script file, do you think we could add or concatenate a "STRING" at the end of the Textbox value? I'd like to see the Textbox showing the currency symbol every time the value changes. By default, the Textbox does not shows the currency symbol on the app . Ref. POS Textbox Parameter Layout by default How I wish It would look like Edited August 16, 2022 by EAHuaroto Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now