Jump to content
Sign in to follow this  

Simplifying While/Wend loops containing ControlCommand()

Recommended Posts


I've been trying to teach myself  the majority of what I know so far and have been making a script to look up some reports in my MICROS sales server at my work.  We have an ancient windows 2000 machine running on the back end that can be painfully slow at times so I've been adding some while/wend loops to check for certain controls before continuing with the script.

There are a large number of steps in the script, this is just an excerpt as an example of how I've been trying to account for occasional lag.  However, there are still a few times where it lags even after the controls become visible and the script then fails due to missing a click here or there.

I think I could change them to Do/Until loops with variables for each class, but so far the entire script is about 350 lines long with about 38 separate while/wend loops checking for different buttons/edits etc. and I was wondering if there is a way to consolidate my very noobish, rough around the edges script.

While 1
    If ControlCommand("MICROS Autosequences and Reports", "", "[CLASS:TMBitBtn;INSTANCE:3]", "IsVisible", "") Then ExitLoop
ControlClick("MICROS Autosequences and Reports", "", "[CLASS:TMBitBtn;INSTANCE:3]", "")

Quick Edit* - I have some other ideas/dreams for this little program that I'm also a bit curious about.  I have an idea in my head about how I'd like this to work when it's close to finalized, including different check boxes on the GUI for each individual department depending on the selection on the combo box that can be checked for which reports need to be printed (Sales, Labor, and Liquor in the attached script) as well as check boxes for whether or not it needs to be printed (the part using send("^p") to the officericoh printer in attached script.)

I haven't started looking into these additions yet as I have just finished this initial learning experience with the main functions of the program, but I figured since I'm here I might as well ask!  All help is greatly appreciated!!! 

MICROS test.au3

Edited by gunnagitcha

Share this post

Link to post
Share on other sites

You could do something like this.

Until ControlClick("MICROS Autosequences and Reports", "", "[CLASS:TMBitBtn;INSTANCE:3]", "")

Instead of checking if each button is visible and then clicking it, attempt to click the button until the ControlClick function returns a 1 for success. It shortens the code needed considerably. Plus you can add some time checking inside the loop to see if the button has appeared or not within a certain timeframe you decide on. See TimerInit/TimerDiff to get the timing.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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