Page 1 of 1

If Error

Posted: Sun Mar 16, 2014 3:32 pm
by itay1023
Hi all :)

Does somebody know how can I code a line which identifies if the code isn't currently available?
For example: if I wrote a code that says: launch URL "skype://" , if the command isn't available because there is no Skype application installed on the iPhone, so another command will be sent.

Best,
Itay :)

Re: If Error

Posted: Sun Mar 16, 2014 3:42 pm
by dave.kilroy
Hi - sounds like a 'try' statement is what you are looking for:

Code: Select all

try
--your code that tries to launch Skype
catch someError
--your alternative code that you call only if Skype isn't available
end try
Although it would be more elegant to have some way of checking for an iPhone's installed apps and whether the user is currently logged in to Skype - but I have no idea how to do that whilst your app is sandboxed)

Re: If Error

Posted: Sun Mar 16, 2014 9:58 pm
by Klaus
Hi itay,

what the dictionary says about "launch url":
...
When launch url is called, LiveCode checks to see if an application is available to handle the URL.
If no such application exists, the command returns "no association" in the result.
...
Like this:

Code: Select all

...
launch URL "skype://..."
if the result <> empty then
  answer "Problem:" && the result
  
   ## Optional:
   exit to top
end if
...
Best

Klaus

Re: If Error

Posted: Sun Mar 16, 2014 10:12 pm
by dave.kilroy
Klaus - nice, I forgot launch URL does that...

Re: If Error

Posted: Mon Mar 17, 2014 12:57 am
by Klaus
THE RESULT is always worth a look! :D

Re: If Error

Posted: Mon Mar 17, 2014 1:19 am
by dave.kilroy
Hi Klaus - yeah you are right however I find I can't always be sure what value the result will have (cf 'it') and I often need to confirm what it SHOULD be (below is an extract from the dictionary):
Many commands (such as go and find) set the value of the result function when they finish. In most cases, if the result is empty, the command was successful; if the result is not empty, the command failed and the result contains an error message. See the specific command for information about whether it sets the result function.
Do you have a simple rule-of-thumb I can use to remind myself what the result is expected to be in common situations?

Re: If Error

Posted: Mon Mar 17, 2014 8:49 am
by Klaus
Hi Dave,

sorry, no simple rule-of-thumb. :(


Best

Klaus