How to return more than 1 variable?

  1. 4 months ago

    Tim S

    Aug 9 Pre-Release Testers, Xojo Pro Phoenix Arizona USA

    Hello all.

    Is it possible to return more than one variable? If so how?
    Thanks,
    Tim

    Pass in the return variables byref in the parameters of the function with a Boolean result of if the function worked.

  2. Dave S

    Aug 9 San Diego, California USA

    return an array or a pair?

  3. Tim S

    Aug 9 Pre-Release Testers, Xojo Pro Phoenix Arizona USA

    HI Dave,
    Only one type can be set as a return type...

  4. Dave S

    Aug 9 San Diego, California USA

    don't understand?

  5. Douglas H

    Aug 9 Pre-Release Testers, Xojo Pro

    @Tim S HI Dave,
    Only one type can be set as a return type...

    Which is why Dave is suggesting the one type hold more than one value. If you only need two, then a Pair is viable. Or an array of variants. Or a dictionary or JSONItem. Or an object that has multiple properties.

    Anything that lets you return multiple values in that "one return value". What works best for any given scenario depends on the scenario...

  6. Graham B

    Aug 9 Pre-Release Testers, Xojo Pro Answer The Canada's

    Pass in the return variables byref in the parameters of the function with a Boolean result of if the function worked.

  7. Johann K

    Aug 9 Perth, Australia

    you can use a class as return value and add as many variables as you like

  8. Kevin G

    Aug 10 Pre-Release Testers, Xojo Pro Gatesheed, England

    Return a dictionary?

  9. Natascha C

    Aug 10 Pre-Release Testers, Xojo Pro Mödling, Lower-Austria, Austr...

    Depending on your needs, you can wrap the variables you want to return in

    • a class
    • a structure
    • a pair
    • a dictionary
    • an array

    The return-value then is defined by the type of wrapper you used.

    Or you use the methods parameters with ByRef.

or Sign Up to reply!