Xojo Function return several values

Hello,
I need function able to return several values.
I tried to assign to the output values ByRef, but it does not work:

[code]Calc(a as double, ByRef x as double, ByRef y as double,ByRef z as double) as double

x= a * 10
y= a * 100
z= a * 1000

return[/code]

What do you mean with “doesn’t work”? Haven’t used byref in ages, though. You could return an array of doubles.

Or you could create a class with the variables x,y,z and use that to return the values.

Your function doesn’t return a value but is declared to return a Double, but otherwise ByRef would surely work.

This function should work:

Sub Calc(a as double, ByRef x as double, ByRef y as double,ByRef z as double) x = a * 10 y = a * 100 z = a * 1000
Use it like this:

Dim x, y, z As Double
Calc(2, x, y, z)
// x is now 20, y is now 200, z is now 1000

Or you can create your own complex type, structure, like:


//Window1.calcTriple:
Function calcTriple(n As Double = 1.0) As Triple
  Dim t As Triple?
  t.x = n*2.34
?  t.y = n*3.14
  t.z = n*4.56
  Return t
End Function

Structure Triple
  x as Double
?  y As Double
?  z As Double
End Structure

//Window1 Control PushButton1:
Sub Action()
?  Dim v As Triple = calcTriple(10)
  ?MsgBox "x= " +Str(v.x)+ " , y= " +Str(v.y)+ " , z= " +Str(v.z)
End Sub

Hello,

[quote]
Beatrix Willius
2 hours ago Beta Testers Europe (Germany)
What do you mean with “doesn’t work”? Haven’t used byref in ages, though. You could return an array of doubles.[/quote]

My function is declared as follows:
LBR_For_Lune( At_JDE as double, ByRef L as double, ByReF B as double, ByRef R as double) as double

Using sub with return value empty, i get this msg:
parameters are not compatible with this function
ClsP.LBR_For_Lune(At_JDE,L,B,R)


using function with return value double, i get this msg:
You must use the value returned by this function
ClsP.LBR_For_Lune(At_JDE,L,B,R)

in a Module Astro i have several class, LBR_For_Lune is in ClsP.
Dim ClsP as New Astro.ClsP

Are you sure that At_JDE, L, B, and R are declared as doubles in the ClsP module somewhere? The method that calls your function does not know the names of the variables – it simply sees that your function is requesting four doubles, which you have to separately define in the calling method.

I also suspect that when you return the double, you are still getting first error, it is just that the second one supersedes it.

Notice

Sub Calc(a as double, ByRef x as double, ByRef y as double,ByRef z as double)

NO “as DOUBLE” on the end
this is a SUB not a FUNCTION the values are ONLY returned via BYREF

[quote=101206:@Djamel AIT AMRANE]Using sub with return value empty, i get this msg:
parameters are not compatible with this function
ClsP.LBR_For_Lune(At_JDE,L,B,R)[/quote]
If you define a function with a return value you either have to use it, or you have to use CALL:

Dim myVar As Double = ClsP.LBR_For_Lune(At_JDE,L,B,R)

or:

Call ClsP.LBR_For_Lune(At_JDE,L,B,R)

[quote=101144:@Djamel AIT AMRANE] :
Calc(a as double, ByRef x as double, ByRef y as double,ByRef z as double) as double
x= a * 10
y= a * 100
z= a * 1000
return[/quote]


Function Calc1(a as double, ByRef x as double, ByRef y as double,ByRef z as double) as double
  Dim AnyValue as Double = 1234.5678
  x= a * 10
  y= a * 100
  z= a * 1000
  return AnyValue
End Function

Sub Calc(a as double, ByRef x as double, ByRef y as double,ByRef z as double)
  x= a * 10
  y= a * 100
  z= a * 1000
  return  // Optional here
End Sub

RETURN is redundant in the 2nd example

As stated in the comment. :wink:

hello,

[quote]
Thomas Moore
57 minutes ago Beta Testers, Xojo Pro, IOS Alpha Testers Claremont, CA

Are you sure that At_JDE, L, B, and R are declared as doubles in the ClsP module somewhere? The method that calls your function does not know the names of the variables – it simply sees that your function is requesting four doubles, which you have to separately define in the calling method.

I also suspect that when you return the double, you are still getting first error, it is just that the second one supersedes it.[/quote]

Function is defined as double, variables as double, L,B,R are ByRef.

H

[quote]If you define a function with a return value you either have to use it, or you have to use CALL:

Dim myVar As Double = ClsP.LBR_For_Lune(At_JDE,L,B,R)

or:

Call ClsP.LBR_For_Lune(At_JDE,L,B,R)[/quote]

I got this:
parameters are not compatibles with this function

Dim myVar As Double = ClsP.LBR_For_Lune(At_JDE,L,B,R)
same with Call ClsP.LBR_For_Lune(At_JDE,L,B,R)

I suspect that one of the variables At_JDE, L, B, or R is not really declared as Double.

For a function like LBR_For_Lune( p1 as double, ByRef p2 as double, ByReF p3 as double, ByRef p4 as double) as double

Called as: Dim r1 as Double = ClsP.LBR_For_Lune(At_JDE, L, B, R)

Any of these [At_JDE, L, B, or R] are not declared as Double. :wink:

I have found that inside the functions had same name of out put values, i change L, B to LL, BB , and it’s running properly.
i am new in Xojo, i discover it, i must thing differently as Vb6.
I am converting Vb appllications to Xojo and learning xojo together.
thank’s everybody.

VB6 and XOJO to my knowledge handle this situation EXACTLY the same way

You are right, the function was modified to run with other special maths functions, so have rewrite some variables, and i make some mistakes.
Thank you.