Multiple/Embedded If's ... should that work?

Post your questions and help other users.

Moderator: Martin

Post Reply
itrysohard
Posts: 4
Joined: 16 Jan 2014 16:55

Multiple/Embedded If's ... should that work?

Post by itrysohard » 16 Jan 2014 17:35

I am using the Input Dialog to have the user provide a Single Choice. This Single Choice is in text and is one of four possibilities:
"Sleeping Pills"
"Test Cassettes"
"NovoRapid"
"Lantus"

When the user chooses one of these option though I want a "number" copied to clipboard, i.e.
If user chooses "Sleeping Pills" then "1234567" is sent to clipboard
If user chooses "Test Cassettes" then "2345678" is sent to clipboard
If user chooses "NovoRapid" then "3456789" is sent to clipboard
If user chooses "Lantus" then "4567890" is sent to clipboard

I tried using an embedded "If" statements in script to do this (i.e. If "Sleeping Pills" then make a variable = "1234567" else if, else if, etc. then copy variable to clipboard), I also tried using compounded Conditions (in a similar fashion as if statements) to do this. But the only time it seems to work is when the first choice ("Sleeping Pills") is chosen, otherwise "null" is copied to the clipboard. It's as though after the first If statement is executed the {value} variable loses it's value or something, I don't get it... any thoughts? Thanks!
I Try Soooo Hard!
Help Me! =)

mcyber
Posts: 37
Joined: 08 Nov 2013 14:21

Re: Multiple/Embedded If's ... should that work?

Post by mcyber » 16 Jan 2014 17:59

Try initializing variable before anything else:

Variable = "some value";
If (condition)
.......;
Else
......;
If (.....)
.....;


And so on

itrysohard
Posts: 4
Joined: 16 Jan 2014 16:55

Re: Multiple/Embedded If's ... should that work?

Post by itrysohard » 16 Jan 2014 19:08

Thanks for the reply mcyber.

I tried that just now but it didn't work. I applied the value from the Single Choice Input Dialog - {value} - to a variable called "choice_text" (choice_text = {value};) first then changed the if statements to evaluate using the "choice_text" variable instead but again, it only works if the first choice "Sleeping Pills" is selected, all other choices result in "null". Mind you the first choice "Sleeping Pills" is also the default value as well ...
I Try Soooo Hard!
Help Me! =)

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Multiple/Embedded If's ... should that work?

Post by MURTUMA » 16 Jan 2014 20:29

Here's a part of one of my flows. You should be able to use this as a reference for working out your case.


http://automagic4android.com/flow.php?i ... e18a30ea96.

itrysohard
Posts: 4
Joined: 16 Jan 2014 16:55

Re: Multiple/Embedded If's ... should that work?

Post by itrysohard » 16 Jan 2014 20:55

Thanks as well MURTUMA,

I used the index method instead (not sure why I didn't before), however now the clipboard text is always "1" no matter what option I choose (whereas before it was "1" for option 1 "Sleeping Pills", but "null" if I selected any other option).

I've attached an xml of my Flow if you want to take a look at it. I don't see anything wrong ...
Attachments
exported_data_20140116_164554.xml
Flow 01-16-2014
(3.28 KiB) Downloaded 860 times
I Try Soooo Hard!
Help Me! =)

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Multiple/Embedded If's ... should that work?

Post by MURTUMA » 17 Jan 2014 06:50

Indexes are zero based, so in your script should read "if index ==0" and so on.

http://automagic4android.com/flow.php?i ... 16e2d53183

itrysohard
Posts: 4
Joined: 16 Jan 2014 16:55

Re: Multiple/Embedded If's ... should that work?

Post by itrysohard » 17 Jan 2014 17:49

Woohoo!! Alas ... it works! Thanks everybody!

Cheers!
I Try Soooo Hard!
Help Me! =)

Post Reply