 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
sinkfaze
Joined: 19 Mar 2008 Posts: 138
|
Posted: Tue May 13, 2008 7:25 pm Post subject: Search multiple options with IfInString |
|
|
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 |
|
 |
trueski
Joined: 08 Apr 2008 Posts: 17
|
Posted: Tue May 13, 2008 7:30 pm Post subject: |
|
|
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 |
|
 |
sinkfaze
Joined: 19 Mar 2008 Posts: 138
|
Posted: Wed May 14, 2008 2:05 am Post subject: |
|
|
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 |
|
 |
Z Gecko Guest
|
Posted: Wed May 14, 2008 2:14 am Post subject: |
|
|
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
|
Posted: Thu May 15, 2008 9:39 am Post subject: |
|
|
Why don't you simply use | Code: | IfInString, Var, DEFGHIJKL
Gosub, DEFProg |  _________________ Hasso
Programmers don't die, they GOSUB without RETURN |
|
| Back to top |
|
 |
n-l-i-d Guest
|
Posted: Thu May 15, 2008 9:48 am Post subject: |
|
|
| 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
|
Posted: Thu May 15, 2008 10:53 am Post subject: |
|
|
| 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).  _________________ Hasso
Programmers don't die, they GOSUB without RETURN |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|