Jump to content

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

Need help with IfinString



  • Please log in to reply
2 replies to this topic
radiosilk
  • Members
  • 22 posts
  • Last active: Nov 06 2015 09:10 AM
  • Joined: 27 Sep 2015

Spent whole day trying but couldn't make it work. Don't know where i am doing this wrong. 

 

First the code:


#SingleInstance
#Warn
#Persistent
myfirststring:="Initialization Failed"
mysecondstring:="Another instance of the exe is running"


;Nise is the only word in headline of target windows. Many other windows have Nise with other words in their headlines
SetTitleMatchMode, 3
IfWinExist,Nise
{
ControlGetText,nwfail,Static1,Nise ;These are 2 different windows
ControlGetText,nwfailtwo,Static2,Nise ;with exactly same headline --> Nise



;About to compare 2 strings partially and not with complete text body
SetTitleMatchMode, 2

IfInString,nwfail,%myfirststring%
{
;need to change mode to send action to correct target window only
SetTitleMatchMode, 3
ControlSend,Button1,{Space},Nise
    sleep,500
MsgBox,Internet Disconnected, App Restarting
}


;same reasons below with different target and different text to compare with
SetTitleMatchMode, 2
IfInString,nwfailtwo,%mysecondstring%
{
SetTitleMatchMode, 3
    ControlSend,Button1,{Space},Nise
    sleep,500
   MsgBox,A working instance found. Closing the latest one.
}

}
 
1.  The program is a Windows-inside-Window type. So, many windows' titles can start or contain same word "Nise". BUT this script takes action only on those particular windows that have only "Nise" as headline. Hence, must use SetTitleMatchMode=3 when have to identify windows accurately to take action on them.

 

2. The alert windows that pop up (the ones i am targeting) have huge text bodies in "Static1" or "Static2" variables. And the text is in 3 separate lines. If i am not wrong  "IfinString" also compares spaces etc so to do away with that complexity i use SetTitleMatchMode=2 just before comparing the strings.

 

3. Now my window pop-up has appeared but the script doesn't do anything at all :(

 

so what have i done wrong here? please help..



Shadowpheonix
  • Members
  • 268 posts
  • Last active:
  • Joined: 10 Feb 2014
✓  Best Answer

SetTitleMatchMode has no affect on IfInString.

 

The best way to try and determine what is wrong with your script would be to use MsgBox  to check your variable contents right before your IfInString.  Something like...

MsgBox %nwfail%
IfInString,nwfail,%myfirststring%

You would of course remove the MsgBox once your script is working correctly.



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

Tried by no success. Will try again tomorrow.