Help with arrays

27 views
Skip to first unread message

djsv...@gmail.com

unread,
Nov 27, 2015, 7:22:41 PM11/27/15
to Tasker
Hello,
I am integrating RS232 device in my home automation that passes a code back to tasker. So far, I got that right. Now what I want to do is match that code to a string. I believe I need to use arrays. Here is a simplified example.

I have a txt file that has data in this format:
001, one
002, two
003, three
...
250, two hundred fifty

I parse the value from the RS232 device into tasker in the same format. Now how do I get it to match the string after the coma? Let's say the RS232 returned 250 and I want to flash " two hundred fifty" on the screen.

I will really need explanation for dummies :).

Regards, 
Simon

SimonBG

unread,
Nov 27, 2015, 7:34:50 PM11/27/15
to Tasker
Btw, Once I load all the info in Tasker, I don't need to read or write to that file.

SimonBG

unread,
Nov 27, 2015, 8:51:56 PM11/27/15
to Tasker
Also, the part of the difficulty I see is the fact the first column, the 3 digit numbers, are not sequential. This document has 150 lines but number range from 001 to 450. So I really need to match that, not the lines.

Juergen Gruen

unread,
Nov 28, 2015, 2:17:54 AM11/28/15
to Tasker
Hi!

A1 Read File, File: myFile, To: %data
A2 Variable Search Replace, Variable: %data, Search: 250.*, Store Results In: %match
A3 Variable Section, Variable: %match1, From: 6, Length: 100, Store Results In: %res, Adapt To Fit: On
A4 Flash %res


Juergen.

Rich D

unread,
Nov 28, 2015, 8:40:57 AM11/28/15
to Tasker Google Groups Post

Huh.. I did not realize that variable section would stop at a line feed. That almost seems  wrong...

Should not a line feed  be included as just data within the variable?

Dale Smith

unread,
Nov 28, 2015, 9:51:46 AM11/28/15
to Tasker
I think I would try the code first then if it didn't work make a comment. I'm guessing that Adapt to fit option stops at EOL.

SimonBG

unread,
Nov 28, 2015, 10:30:09 AM11/28/15
to Tasker
Thanks guys. My problem was with arrays but syntaksys, not logic. I was evoking %Match instead of %Match() or %Match#

So I did it pretty simple
Load file into variable (once)
Search for my value + .* (this includes everything else till line break). This gives me %Match1 "250, two hundred fifty". Then split %Match1 > %Match11 and %Match12. I use %Match12 "two hundred fifty"

Dale Smith

unread,
Nov 28, 2015, 10:52:22 AM11/28/15
to Tasker
I think all Tasker users struggled with arrays at one point or another. Glad it's working for you now.

Juergen Gruen

unread,
Nov 28, 2015, 4:12:52 PM11/28/15
to Tasker

%match1 only contains the result of the Search-Replace-Action. There is no linefeed...

Rich D

unread,
Nov 28, 2015, 6:39:36 PM11/28/15
to Tasker Google Groups Post


> I think I would try the code first then if it didn't work make a comment. 

Sorry , I was not clear.  Given the poster I was sure the code would work but did test it any way. My comment was more of a question about the variable section action.

Rich D

unread,
Nov 28, 2015, 6:40:40 PM11/28/15
to Tasker Google Groups Post


> %match1 only contains the result of the Search-Replace-Action. There is no linefeed...

Thanks for clearing that up.  I was just misinterpreting the regex....   

Reply all
Reply to author
Forward
0 new messages