Working with arrays and need some help

143 views
Skip to first unread message

John Day

unread,
Jul 30, 2014, 11:55:56 PM7/30/14
to tas...@googlegroups.com
if i have an array set up. The four variables %arr1, %arr2, %arr3, %arr4 hold respectively a, b, c and d then we have an array with 4 elements.

Now I want to write a task that includes a if statement.   %var

I want the task to only run if %var does not match any of the variables in the array above.

so if %var was = to a then the task would not run. because %arr1 = a

if %var = z the the task would run because %arr() = a, b, c, d

now I am not sure how to get %var to check against all possible varialbes in the %arr

here is what I came up with that did not work

if %var !~ %arr()   also tried
if %var !~ *%arr()


I hope i haven't completely confused everyone and hope there is some insight available thanks.

Bob Hansen

unread,
Jul 31, 2014, 12:21:40 AM7/31/14
to tas...@googlegroups.com
You would need to use a For Loop to of a variable value against each element in the Array. To avoid doing this convert the array into a variable with each value separated with a forward slash /. This can easily be done using the Variable Join action. Variable: %arr Joiner:/
The If statement:
If %test !~ %arr will check against all the %arr values.

Brandon Horwath

unread,
Jul 31, 2014, 12:53:11 AM7/31/14
to tas...@googlegroups.com
Isn't this just %arr(#?%test)?

Brandon Horwath

unread,
Jul 31, 2014, 12:59:36 AM7/31/14
to tas...@googlegroups.com
I think so:

A1: Variable Set [ Name:%arr To:a,b,c,d Do Maths:Off Append:Off ]
A2: Variable Split [ Name:%arr Splitter:, Delete Base:Off ]
A3: For [ Variable:%var Items:d,e ]
A4: Flash [ Text:Match found for: %var
Index position: %arr(#?%var) Long:On ] If [ %arr(#?%var) > 0 ]
A5: Flash [ Text:NO match found for %var Long:Off ] If [ %arr(#?%var) eq 0 ]
A6: End For

Brandon Horwath

unread,
Jul 31, 2014, 1:06:11 AM7/31/14
to tas...@googlegroups.com
Here, this example supports multiple matches ;-)

Array Test (525)
A1: Variable Set [ Name:%arr To:a,b,c,d,d,d Do Maths:Off Append:Off ]

A2: Variable Split [ Name:%arr Splitter:, Delete Base:Off ]
A3: For [ Variable:%var Items:d,e ]
A4: Flash [ Text:Match found for: %var
Index position: %arr(#?%var) Long:On ] If [ %arr(#?%var) > 0 ]

A5: Flash [ Text:Multiple matches found for: %var
Index positions: %arr(#?%var) Long:On ] If [ %arr(#?%var) ~ *,* ]
A6: Flash [ Text:NO match found for %var Long:Off ] If [ %arr(#?%var) eq 0 ]
A7: End For

Hope this helps.

Robert Hansen

unread,
Jul 31, 2014, 1:06:24 AM7/31/14
to tas...@googlegroups.com
Why didn't I think of that!

If %arr(#?%test) = 0 then %test is not in the array!!

Time to go to bed and try to revitalize some brain cells.


On Wed, Jul 30, 2014 at 9:53 PM, Brandon Horwath <brandon...@gmail.com> wrote:
Isn't this just %arr(#?%test)?

--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages