New topic: Return values
<http://forums.realsoftware.com/viewtopic.php?t=47425> Page 1 of 1 [ 5 posts ] Previous topic | Next topic Author Message McDian Post subject: Return valuesPosted: Wed Mar 27, 2013 5:49 pm Joined: Fri Sep 14, 2007 5:00 pm Posts: 399 Can a method return more than one value. What I mean by this is I have a method that is used to calculate both a hi and lo value based on specified criteria. I want to return two separate variable from the method (both are doubles) but I am not sure how to do this or if it can even be done. Top timhare Post subject: Re: Return valuesPosted: Wed Mar 27, 2013 5:56 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 12183 Location: Portland, OR USA A method can only return one value, but that value can be an object that contains many bits of data. You could return a Pair or a Point or even a Dictionary, or create your own class. dim d as new dictionary d.value("hi") = hiValue d.value("low") = lowValue return d Top McDian Post subject: Re: Return valuesPosted: Wed Mar 27, 2013 6:14 pm Joined: Fri Sep 14, 2007 5:00 pm Posts: 399 Can you point me to the documentation about dictionaries? If I read up maybe my other questions will be answered by reading. I don't know anything about dictionaries (well as referred to by RB!) Top timhare Post subject: Re: Return valuesPosted: Wed Mar 27, 2013 6:24 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 12183 Location: Portland, OR USA Start with the wiki page: http://docs.realsoftware.com/index.php/Dictionary A dictionary is a collection of name/value pairs. The simplest usage is to just use the Value methods and supply a name, or key. dim d as new dictionary dim hival as double = 12.5 d.value("high") = hival dim x as double x = d.value("high") Top DaveS Post subject: Re: Return valuesPosted: Wed Mar 27, 2013 7:00 pm Joined: Sun Aug 05, 2007 10:46 am Posts: 4707 Location: San Diego, CA A method can return many values.... just one as a direct return argument, and that one can be an class object as Tim mentioned. But you can use BYREF to return others if necessary. Function myFunction(a as integer,byref b as string,byref c as integer) as myclassobject this would take "A" (and optionally B and C) as input parameters, and return myclassobject, but at the same time allow the function to alter the contents of B and C and return them with new values. _________________ Dave Sisemore MacPro, OSX Lion 10.7.4 RB2012r1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 5 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
