Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

If Count > Previous Count, Do stuff - Is this right ?



  • Please log in to reply
6 replies to this topic
radiosilk
  • Members
  • 22 posts
  • Last active: Nov 06 2015 09:10 AM
  • Joined: 27 Sep 2015
Firstly, Thanks to the creators, maintainers and innovators of AHK !
 
This is a newbie effort in ahk and coding in general. Have been able to do basic stuff using ahk. 
 
Request for a review. Will the code below work? 
 
During daytime, the window gets populated asynchronously / ad-hoc. But when a new entry happens i want to send a refresh to this list and other associated windows. This action brings the latest entry in focus in all associated windows.
 
Just want to refresh when count is greater than last count.
 
IfWinExist, Playtt
ControlGet, cnt, List,count , SysListView321, Playtt
if (cnt>cnt)
{
WinGet,adpo,id,Playtt
controlsend,,{F5 down}{F5 up},ahk_id %adpo%
Sleep,500
return
}

 



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012
✓  Best Answer

This won't work. You need to create a new variable to make a comparison. You would have to store the previous value of cnt into a variable like old_cnt or prev_cnt.

 

Additionally, do you have a SetTimer or Loop going on around this? SetTimer seems the most logical to use.

 

Finally, I don't think the IfWinExist is necessary. If you think it is, I would wrap some brackets to include ControlGet all the way to the end of the code you gave. Otherwise, the if (cnt>prev_cnt) line would always be executed.

 

This is untested code and I have not verified your syntax of ControlGet.

 

#Persistent ; keeps the script open
SetTimer, Playtt_Refresh, 15000 ; every 15 seconds, make it shorter or longer as you see fit
return
 
Playtt_Refresh:
IfWinExist, Playtt
{
ControlGet, cnt, List,count , SysListView321, Playtt
if (cnt>prev_cnt)
{
WinGet,adpo,id,Playtt
controlsend,,{F5 down}{F5 up},ahk_id %adpo%
Sleep,500
}
prev_cnt:=cnt ; if you want this to only ever increase in value, put it inside the brackets. Else, if you close some Playtt windows, then prev_cnt can decrease in value.
}
return

 

(Oh, you'll also notice I moved the return to outside of the brackets, because you'd want a return for the situations when no Playtt windows exist.)

 

#Persistent



radiosilk
  • Members
  • 22 posts
  • Last active: Nov 06 2015 09:10 AM
  • Joined: 27 Sep 2015

Thanks a lot, Exaskryz, for helping :shy: . Going to work on this now. Before that will leave a few comments :

 

1.  This code is already inside another if-else which works on a settimer. Didn't post the whole thing here as only for this portion needed help :p .

2.  Will write my code as per your suggestion. "wrap some brackets to include ControlGet all the way to the end of the code " 

3.  Will find out if the syntax is correct or not (though i feel it is)

4.  Because this code block is going to be inside another if-else, there already is a "return" just after the place this code is going to be. So, i'm going to remove this particular "return". If things don't work then will put it back here...

 

Thanks a ton for providing the corrected code and your review.. i guess i have a lot to learn..  :/ 



radiosilk
  • Members
  • 22 posts
  • Last active: Nov 06 2015 09:10 AM
  • Joined: 27 Sep 2015

Do you think this warning is a cause for concern ?

Warning: This variable has not been assigned a value.

Specifically: prev_count (a global variable)

How to set value for prev_count  ? At the start of operation ? But how ?

 

pls inform.. 



kon
  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

Hi radiosilk,

 

The warning you are seeing shows up if you have used #Warn in your script. You could assign the variable a default value in the auto-execute section of the script, or just remove #Warn.



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

For a default value as per kon's suggestion, I would give prev_count a zero. The math should work the same as prev_count having no value.

 

And yes, there is so much to learn to use AHK effectively. It's a wonderful tool. I got started with it maybe three years ago, and only really delved deeper to it a year and a half ago. And I still have a lot of stuff to learn.

 

But that's what's brilliant about AHK. It's fairly easy to learn once you know what you're looking for. The documentation is pretty good so you can really understand what commands and other things are doing. Heck, sometimes I just wander through the documentation and stumble across something I'd like to read more about.



radiosilk
  • Members
  • 22 posts
  • Last active: Nov 06 2015 09:10 AM
  • Joined: 27 Sep 2015

Thanks a lot Kon and Exaskryz. I really like ahk as it is so much simple for a non-programmer like me. Guess i would be on a similar learning curve.

 

Regarding this script, i would need prev_count to retain value because even though window closes for any reason it will again be opened and it will reappear with new id. It is a windows inside a main window kind of app.

 

So, if the warning is not serious enough to ruin my work, i would rather remove the warning for now.

 

Thanks guys..