# How to stop calculating the mouseClicked event?

**URL:** <https://forum.inductiveautomation.com/t/how-to-stop-calculating-the-mouseclicked-event/2790>\
**Category:** Archived Topics\
**Created:** [March 22, 2011, 9:04am UTC](https://forum.inductiveautomation.com/t/how-to-stop-calculating-the-mouseclicked-event/2790 "2011-03-22T09:04:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluefrog](https://avatars.discourse-cdn.com/v4/letter/b/a6a055/32.png) [@bluefrog](https://forum.inductiveautomation.com/u/bluefrog)\
**Post date:** [March 22, 2011, 9:04am UTC](https://forum.inductiveautomation.com/t/how-to-stop-calculating-the-mouseclicked-event/2790/1 "2011-03-22T09:04:41Z")

</div>

I have a button with some script. I used it to get the data from database when the mouseclicked event is fired. But before getting the data, I have to check some condition in that script. And I have to stop that script from calculating if that condition doesn’t meet. I used the sys.exit() but I got the error. I want to stop that script like exit sub or exit function in VB. Is there a way to do it?

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [March 22, 2011, 3:28pm UTC](https://forum.inductiveautomation.com/t/how-to-stop-calculating-the-mouseclicked-event/2790/2 "2011-03-22T15:28:07Z")

</div>

sys.exit will do the trick. What is the error you are getting? Are you importing sys?

---

<div class="post-metadata">

**Author:** ![bluefrog](https://avatars.discourse-cdn.com/v4/letter/b/a6a055/32.png) [@bluefrog](https://forum.inductiveautomation.com/u/bluefrog)\
**Post date:** [March 30, 2011, 6:28am UTC](https://forum.inductiveautomation.com/t/how-to-stop-calculating-the-mouseclicked-event/2790/3 "2011-03-30T06:28:46Z")

</div>

Yes. I’m importing sys. But as far as I know, sys.exit will pop up a message box when I use it. The problem is I want to stop the script but I don’t want to get the pop up message. ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [March 30, 2011, 4:27pm UTC](https://forum.inductiveautomation.com/t/how-to-stop-calculating-the-mouseclicked-event/2790/4 "2011-03-30T16:27:02Z")

</div>

Here is an example that works for me:[code]import sys  
text = event.source.parent.getComponent(‘Text Field’).text

if text == “”:  
sys.exit()

print “here”[/code]

---

<div class="post-metadata">

**Author:** ![bluefrog](https://avatars.discourse-cdn.com/v4/letter/b/a6a055/32.png) [@bluefrog](https://forum.inductiveautomation.com/u/bluefrog)\
**Post date:** [April 4, 2011, 9:27am UTC](https://forum.inductiveautomation.com/t/how-to-stop-calculating-the-mouseclicked-event/2790/5 "2011-04-04T09:27:58Z")

</div>

Yes. It works for me too. But it’s not what I mean. The problem is I got an error when I run that script. And I don’t want that error message to be appeared. I just wanted to stop the script. I want to know that how to stop the script from running without that error message appears. I took the screenshot and attached it here.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [April 4, 2011, 3:38pm UTC](https://forum.inductiveautomation.com/t/how-to-stop-calculating-the-mouseclicked-event/2790/6 "2011-04-04T15:38:05Z")

</div>

Oh ok, well wrap the code in a try except like this:`try:
    your code
except:
    pass`That might get rid of the error message.

---

<div class="post-metadata">

**Author:** ![bluefrog](https://avatars.discourse-cdn.com/v4/letter/b/a6a055/32.png) [@bluefrog](https://forum.inductiveautomation.com/u/bluefrog)\
**Post date:** [April 6, 2011, 2:07am UTC](https://forum.inductiveautomation.com/t/how-to-stop-calculating-the-mouseclicked-event/2790/7 "2011-04-06T02:07:16Z")

</div>

Thanks. It works. 😃😃
