I have the following switch:
-- tempext is a 3 char extension
switch (tempext)
case exe
launch templaunch
break
case txt
launch document templaunch
break
case doc
launch document templaunch
break
case com
launch url templaunch
break
case uk
launch url templaunch
break
case net
launch url templaunch
break
case tml
launch url templaunch
break
case php
launch url templaunch
break
end switch
I have 10 buttons I need to apply this to.
How do I put the switch into a function and get the return to perform the relevant launch action?
I know I could get rid of the switch and use if statements and this would be easy to include in a statement but I'm interested if a switch in a function can return?
Switch in function - return? -- SOLVED --
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Switch in function - return? -- SOLVED --
Last edited by AndyP on Sun Nov 09, 2008 9:48 pm, edited 1 time in total.
Top of my head first thought would be to get the function to return the appropriate launch command and then "do" it.
A very cursory dry run here shows it working in principle.
Code: Select all
on mouseUp
local tempext, templaunch
answer file "Launch the file..."
put it into templaunch
set the itemDelimiter to "."
put the last item of templaunch into tempext
-- you'd need to do more error trapping obviously
do fnLauncher (tempext)
end mouseUp
function fnLauncher pExt
switch (pExt)
case "exe"
return "launch templaunch"
break
case "txt"
return "launch document templaunch"
break
case "doc"
return "launch document templaunch"
break
--etc etc
end switch
end fnLauncher
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
One other thing about 'switch' that you may find interesting is the "fall through" priciple: unless you put a 'break' there, the code of the next 'case' is also executed; also handy is the 'default' case to capture anything you haven't explicitly coded. So your code can look something like this.
HTH,
Jan Schenkel.
Code: Select all
switch tempext
case "exe"
launch tempLaunch
break
case "txt"
case "doc"
launch document templaunch
break
default
launch url templaunch
break
end switch
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
Thanks SparkOut, can see how this works.
Cheers Jan, did not know about the fall through, tidies things up nicely.
Always great replies and help on the Revolution forum. I used to use Real Basic and was always 'fighting' for information.
Hopefully I will be in a position to help other posters in the near futue.
Cheers Jan, did not know about the fall through, tidies things up nicely.
Always great replies and help on the Revolution forum. I used to use Real Basic and was always 'fighting' for information.
Hopefully I will be in a position to help other posters in the near futue.