Jump to content

Beep sound if Textbox value changes


Go to solution Solved by Zedna,

Recommended Posts

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 by EAHuaroto
Link to post
Share on other sites
$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

 

Link to post
Share on other sites
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 post
Share on other sites
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

 

Musashi-C64.png

"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 post
Share on other sites

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 post
Share on other sites
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 post
Share on other sites
  • Developers

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.

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 post
Share on other sites

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

 

Link to post
Share on other sites
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 post
Share on other sites
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 by Musashi

Musashi-C64.png

"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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites
  • Solution
Posted (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 by Zedna
Link to post
Share on other sites
Posted (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

POS Textbox Parameter Layout by default.png

 

 

 

How I wish It would look like

How I wish It would look like.png

Edited by EAHuaroto
Link to post
Share on other sites

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...