Sign in to follow this  
Followers 0
Bookman

Script Exit

6 posts in this topic

I am having trouble with this script. It works fine as long as there is only one instance of it running. Unfortunately, it doesnt close when $DB closes, so re-opening the $DB loads the script again. Sometimes I find three or four instances running, and have problems with it then. Any ideas?

Thanks in advance

Global Const $DB='FileMaker Pro Advanced - [Price_List]'

;Wait for the DB software to close

WinWaitClose($DB)

Exit

;Define the hot key set

HotkeySet("{F5}", 'Search')

HotkeySet("{F9}", 'Card')

WinWait ($DB)

Func Search()

Local $Input = InputBox('Scanning', 'Incoming data:')

If @Error Then Return

WinActivate($DB)

Send("^s")

Sleep(300)

Send($Input, 1)

Send("{ENTER}", 0)

EndFunc

Func Card()

WinActivate($DB)

Send("^h")

EndFunc

Share this post


Link to post
Share on other sites



You could wrap them in an "If" statement.

Global $DB = 'FileMaker Pro Advanced - [Price_List]'

;Define the hot key set
HotkeySet("{F5}", 'Search')
HotkeySet("{F9}", 'Card')

WinWait($DB)
While WinExists('FileMaker Pro Advanced - [Price_List]')
    Sleep(100)
WEnd

Func Search()
    If WinExists('FileMaker Pro Advanced - [Price_List]') Then
        Local $Input = InputBox('Scanning', 'Incoming data:')
        If @Error Then Return
        WinActivate($DB)
        Send("^s")
        Sleep(300)
        Send($Input, 1)
        Send("{ENTER}", 0)
    EndIf
EndFunc

Func Card()
    If WinExists('FileMaker Pro Advanced - [Price_List]') Then
        WinActivate($DB)
        Send("^h")
    EndIf
EndFunc

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try adding this routine at the beginning of your script. It will exit the script immediately if one instance is already running.

$sVersion = "Price_list"

If WinExists($sVersion) Then Exit

AutoItWinSetTitle($sVersion)

Edited by gspino

Share this post


Link to post
Share on other sites

Try adding this routine at the beginning of your script. It will exit the script immediately if once instance is already running.

$sVersion = "Price_list"

If WinExists($sVersion) Then Exit

AutoItWinSetTitle($sVersion)

I don't have a problem with more than one version of the price list running, I have hte problem with three or four instances of the script running at the same time. Is there any way to prevent this?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

from the top FAQ's... and as gspino stated ( just used the term "price list")

14. How can I make sure only one copy of my script is run?

The easiest way is to rename the title of the hidden AutoIt window when your script first starts. Then in the same script check for that window title existing - if it does then another copy of the script is running.

; Place at the top of your script

$g_szVersion = "My Script 1.1"

If WinExists($g_szVersion) Then Exit ; It's already running

AutoItWinSetTitle($g_szVersion)

; Rest of your script goes here

Back To Top

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

This is perhaps the changes inserted that the others have mentioned.

; Only 1 instance. <-- as gspino mentioned
$sVersion = "Price_list"
If WinExists($sVersion) Then Exit
AutoItWinSetTitle($sVersion)

;Define the hot key set
HotKeySet("{F5}", 'Search')
HotKeySet("{F9}", 'Card')

WinWait($DB)

; Idle until $DB closes. <-- hotkeys will still work fine
While WinExists($DB)
    Sleep(500)
WEnd

Func Search()
    Local $Input = InputBox('Scanning', 'Incoming data:')
    If @Error Then Return
    WinActivate($DB)
    Send("^s")
    Sleep(300)
    Send($Input, 1)
    Send("{ENTER}", 0)
EndFunc

Func Card()
    WinActivate($DB)
    Send("^h")
EndFunc

Share this post


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
Sign in to follow this  
Followers 0