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 

Search multiple options with IfInString

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



Joined: 19 Mar 2008
Posts: 138

PostPosted: Tue May 13, 2008 7:25 pm    Post subject: Search multiple options with IfInString Reply with quote

I have a script I'm running where I use IfInString to search a variable for certain data to tell my script what to do from there. I have four different strings that if found will go to the same subroutine, can I place those all within one IfInString statement? If so, how? Or will I have to string all of them together with 'else IfInString'? The latter obviously works, it just doesn't look very clean.
_________________
Have trouble searching the site for information? Try Quick Search for Autohotkey.
Back to top
View user's profile Send private message
trueski



Joined: 08 Apr 2008
Posts: 17

PostPosted: Tue May 13, 2008 7:30 pm    Post subject: Reply with quote

found this example in the help file

Code:
if (Color = "Blue" or Color = "White")
{
    MsgBox The color is one of the allowed values.
    ExitApp
}
else if (Color = "Silver")
; .....


Should be able to get it to work with ifinstring
_________________
-Trueski-
Back to top
View user's profile Send private message
sinkfaze



Joined: 19 Mar 2008
Posts: 138

PostPosted: Wed May 14, 2008 2:05 am    Post subject: Reply with quote

Well that was frustrating. Here are all of the combinations I tried that did not work with IfInString:

Code:
IfInString, Var, DEF or GHI or JKL
 Gosub, DEFProg

Code:
IfInString, Var, DEF || GHI || JKL
 Gosub, DEFProg

Code:
IfInString, Var, (DEF or GHI or JKL)
 Gosub, DEFProg

Code:
IfInString, Var, (DEF || GHI || JKL)
 Gosub, DEFProg

Code:
IfInString, Var, DEF
or GHI
or JKL
 Gosub, DEFProg

Code:
IfInString, Var, DEF
|| GHI
|| JKL
 Gosub, DEFProg


The only code that did work was this:

Code:
IfInString, Var, DEF
 Gosub, DEFProg
else IfInString, Var, GHI
 Gosub, DEFProg
else IfInString, Var, JKL
 Gosub, DEFProg


Am I misunderstanding how IfInString is supposed to work or am I missing something in the syntax?
_________________
Have trouble searching the site for information? Try Quick Search for Autohotkey.
Back to top
View user's profile Send private message
Z Gecko
Guest





PostPosted: Wed May 14, 2008 2:14 am    Post subject: Reply with quote

You are misunderstanding how IfInString works, it supports only one searchstring.
The "contains" operator in expression-if is the same as using IfInString/IfNotInString except that multiple search strings are supported (any one of which will cause a match).
Back to top
Hasso



Joined: 23 Mar 2005
Posts: 128
Location: Germany

PostPosted: Thu May 15, 2008 9:39 am    Post subject: Reply with quote

Why don't you simply use
Code:
IfInString, Var, DEFGHIJKL
 Gosub, DEFProg
Question Question Question
_________________
Hasso

Programmers don't die, they GOSUB without RETURN
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Thu May 15, 2008 9:48 am    Post subject: Reply with quote

Code:
If Var in D,E,F,G,H,I,J,K,L
 Gosub, DEFProg
Back to top
Hasso



Joined: 23 Mar 2005
Posts: 128
Location: Germany

PostPosted: Thu May 15, 2008 10:53 am    Post subject: Reply with quote

n-l-i-d wrote:
Code:
If Var in D,E,F,G,H,I,J,K,L
 Gosub, DEFProg
I fear that wouldn't do it! As DEF is neither in D nor in E nor in F ... nor in L.
You could write
Code:
If Var in DEF,GHI,JKL
 Gosub, DEFProg
but I think my code above is a little bit shorter (doesn't need the commas). Mr. Green
_________________
Hasso

Programmers don't die, they GOSUB without RETURN
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