AutoHotkey Community

It is currently May 26th, 2012, 5:40 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: April 24th, 2009, 10:05 am 
Offline

Joined: February 12th, 2008, 2:25 pm
Posts: 13
Location: Munich, Germany
Hi there -

Actually I wasn't reading the 'if Var in MatchList'-article in the Wiki well enough and therefore had a strange error ('matchlist contains illegal characters') that after some research turned out to be not due to the matchlist but due to the expression

IF (var NOT IN matchlist AND ...) {}...

So as mentioned in the article the 'IN ' expression doesn't work combined with other if-clauses - same with 'contains' and using InStr() by the way.


A possible workaround would be some logic like

if var not in matchlist => listcheck:= true else false
if listcheck AND ....

Maybe trivial for more experienced users, but I had a hell of a time finding that error and was stuck with if...if...if-structures as a solution first.

Hope this helps! :)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 24th, 2009, 10:50 am 
thewer wrote:
IF (var NOT IN matchlist AND ...) {}...

So as mentioned in the article the 'IN ' expression doesn't work combined with other if-clauses - same with 'contains' and using InStr() by the way.
That interpretation is wrong. 'IN ' does not work in if expressions, but can be used in if (else) structures.

This should be in Ask for Help
Ask for Help topic description wrote:
Ask questions and (hopefully) get answers. Post helpful tips and tricks.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 24th, 2009, 11:49 am 
Offline

Joined: February 12th, 2008, 2:25 pm
Posts: 13
Location: Munich, Germany
Well, I actually had an if - / else if- structure, not sure what that would count for - as it is both else and if...?
So it didn't work for
if (...in And ...) {}
else if {}

Anyway (maybe something else was messed up, too) - even if only for the if-structure, if the AND is really needed, making a bolean from the makelist-query should help.
It would be great, if in the wiki would be stated also, why certain expressions won't work - would be easier for workarounds. :)

How can I move a thread in another category?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 24th, 2009, 12:07 pm 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3329
Location: Simi Valley, CA
Actually, now the thread can stay:
Code:
InList(var, matchlist)
{ ; function by [VxE]. Alternate for 'If Var [Not] In Matchlist'
; return value is 0 if the string contained in var does not match
; any item in matchlist. Otherwise, the return value is the number
; of the item in matchlist that first matched var.
   StringReplace, var, var, `,, % Chr(4), all
   StringReplace, matchlist, matchlist, `,`,, % Chr(4), all
   matchlist := SubStr("_," matchlist, 1, 1 + InStr("," matchlist ",","," var ","))
   StringReplace, matchlist, matchlist, `,,`,, UseErrorLevel
   return ErrorLevel
}
needle = bar
haystack = yoo,foo,bar
MsgBox % "'"needle "' found in '" haystack "' at item " InList(needle, haystack)


I've only done a bit of testing, but the output seems to be consistent with the behavior stated in the comments. Its behavior also seems to be analogous to the 'If _ [Not] In _' that it emulates. I've tested matching an empty string, as well as a string with commas. If someone would like to test further and post the error cases, I'll be happy to update.

I was actually thinking about this after reading jaco0646's post... though that was resolved previously.

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, XX0 and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group