AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Troubleshooting Tool?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
scouchman



Joined: 28 Apr 2004
Posts: 44

PostPosted: Thu Aug 19, 2004 9:03 pm    Post subject: Troubleshooting Tool? Reply with quote

Is there a way to do a line by line execution of an AHK script? (without really modifying the script?)

My problem is that I have a script that works about 95% of the time, but that 5% it doesn't work is driving me nuts.

And I know its not AHK, it's the program AHK is pulling the data from, I just can't figure out the situation.

Below is the pertanent part of the code, the comments are all for the forum's benefit, I don't have the comments in actual code I use.

The various gosubs are because this is one of about 15 scripts that many of the scripts pull from.

The problem seems to be around the PSCCommentGrab. MOST of the time it grabs the correct fields, but every once in a while it grabs Edit11 for the comment, Edit19 for the tech, and Edit20 for the timestamp. That appears to be a constant. If it screws up, it does it the same way every time. Once it screw up, it seems to stay screwed up until I restart the Vantive program.

So once it screws up, if I can step through the AHK script, I might be able to find why the Vantive program goes flaky (and maybe get AHK to anticipate and deal with it when it does)

Right now when I find a problem I can put a MsgBox as a "pause", but I don't want to do that until it starts acting up, and adding pauses all over the place would be a headache.

Code:
#d::
IfWinActive, Vantive System
{
Gosub, Clear  ; just verifies that all the variables are cleared
Gosub, VantiveTypeTest   ; tests which version of the program I'm in

IfEqual, Test, // `:`: 
Gosub, PSC2SIVComment 
Else
Gosub, SIV2PSCComment ; SIV2PSCComment reads data totally different, so to save space won't include it
}
Return

PSC2SIVComment:
Gosub, PSCTicket ; Get PSC Ticket Number
WinGet, PSC, ID, Vantive System - [Problem Report ID: %PSCIR%.00000]
Gosub, PSCCommentGrab
WinActivateBottom, Vantive System
Gosub, SIVCommentCheck ; Just makes sure the Edit11 field is blank and blanks it if necesary
ControlFocus, Edit11, ahk_id %SIV%
Sleep, 500
Clipboard = At %Timestamp% Central Time, %Tech% commented the PSC ticket with the following comment:
Send,  {CTRLDOWN}v{CTRLUP}{ENTER 2}
Clipboard = %comment%
Send, {CTRLDOWN}v{HOME}{CTRLUP}
Return

PSCTicket: 
    WinGetTitle, PSCIR, A
    StringRight, PSCIR, PSCIR, 14
    StringLeft, PSCIR, PSCIR, 7
Return

PSCCommentGrab:
ControlGetText, Comment, Edit32, ahk_id %PSC%
ControlGetText, Tech, Edit33, ahk_id %PSC%
ControlGetText, Timestamp, Edit34, ahk_id %PSC%
Return

_________________
Scott F Couchman
Back to top
View user's profile Send private message AIM Address MSN Messenger
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Thu Aug 19, 2004 10:16 pm    Post subject: Reply with quote

Quote:
Is there a way to do a line by line execution of an AHK script? (without really modifying the script?) ... Right now when I find a problem I can put a MsgBox as a "pause", but I don't want to do that until it starts acting up, and adding pauses all over the place would be a headache.

There isn't currently, but you can use the Pause command rather than MsgBox, which is less intrusive. So perhaps put a few pauses at critical places in the script. Then when the tray icon turns red to indicate it's paused, open the main window and view the lines most recently executed. After studying it (and perhaps the View > Variables screen also), resume the script by pressing the Pause key or selecting the Pause menu item. The script will pause again when it reaches the next Pause line.

Though crude, this is a good way to put "breakpoints" in your script so that you can go through it more easily (though admittedly not step by step). I'll add an item to the to-do list to have line-by-line execution mode so that it will pause automatically after every line.

Quote:
the comments are all for the forum's benefit, I don't have the comments in actual code I use.

In case you were worried about comments taking up more memory or slowing down the script's execution, they do not (because they aren't even loaded into memory when the script starts).

Quote:
The problem seems to be around the PSCCommentGrab. MOST of the time it grabs the correct fields, but every once in a while it grabs Edit11 for the comment, Edit19 for the tech, and Edit20 for the timestamp. That appears to be a constant. If it screws up, it does it the same way every time. Once it screw up, it seems to stay screwed up until I restart the Vantive program.

If the controls in question have a name, you might try using that (or a substring of it) instead of the ControlClass + sequence number. A control's name is usually the caption or prompt that appears next to it (but also viewable in the Window Text section of Window Spy).
Back to top
View user's profile Send private message Send e-mail
Beastmaster



Joined: 15 Apr 2004
Posts: 182

PostPosted: Fri Aug 20, 2004 7:21 am    Post subject: Reply with quote

Had to fight a similar issue. So I check the target window (about its content/text) right after I've entered the text (ControlSetText) at the editbox.

The main issue seems to be that a control is losing its focus, during the window will be "drawn" ... Crying or Very sad

Therefore I had a request about a command like this (TBH, meanwhile some/most/all? of that seems to be covered by existing AHK Win... commands)

---
WaitReady, paint_events

WaitReady suspends script execution until the foreground window has finished processing mouse, keyboard, show window, and optionally, paint events. Issue 1 to include paint events, and 0 to exclude paint events. This command can therefore be used to wait until the active application is ready to receive keyboard and mouse events in most situations.
---

Another option is to loop if an assigned control (e.g. the Save button beside an edit field) becomes "active/enabled" (ControlGetFocus), cause the assigned field has got some content.
Back to top
View user's profile Send private message
Rajat



Joined: 28 Mar 2004
Posts: 1717

PostPosted: Fri Aug 20, 2004 10:13 am    Post subject: Reply with quote

congrats on new version Chris! process commands are welcome.

Quote:
Though crude, this is a good way to put "breakpoints" in your script so that you can go through it more easily (though admittedly not step by step). I'll add an item to the to-do list to have line-by-line execution mode so that it will pause automatically after every line.


this is where the debugger idea that i gave u (that u seemed to like too) comes in. maybe we can discuss it to seek the best and easiest/fastest implementation.
_________________
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Fri Aug 20, 2004 1:21 pm    Post subject: Reply with quote

Quote:
WaitReady suspends script execution until the foreground window has finished processing

Although that feature sounds good on paper, from a technical standpoint it seems likely to be useless. The reason for this is that events sent to a window are not lost simply because that window is busy; instead, they are queued up for later processing. This is a fundamental feature of the OS and hardly ever violated except for apps that do their own custom keystroke handling (such as some games). Even for them, WaitReady is unlikely to help because the App is doing something time-sensitive and independent from its queued messages.

However, the reason for having SetControlDelay seems to indicate that controls need time to adjust (in some cases) after they've been altered. That might be due to the app needing time to send messages to itself to set things up correctly after a control has been targetted with something like ControlClick. If this theory is true, I suspect WaitReady would fail to help because it would not necessarily detect the app is in the process of sending messages to itself.

In short, I'd want to see real-world evidence that such a feature actually helps before I added it.

Quote:
this is where the debugger idea that i gave u (that u seemed to like too) comes in. maybe we can discuss it to seek the best and easiest/fastest implementation.

Thanks, I ensured the two to-do items are paired together and I updated the Planned Features List. If you have more ideas beyond the ones already given, feel free to send them. Or we can just wait until that feature is next in line.
Back to top
View user's profile Send private message Send e-mail
Rajat



Joined: 28 Mar 2004
Posts: 1717

PostPosted: Fri Aug 20, 2004 4:06 pm    Post subject: Reply with quote

yes, just let me know when u're ready to add the debugger feature and then we can discuss its application.
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group