Function returning an array

N

Nathan

Hello,

I have a function that reduces a fraction to lowest terms, storing the
fraction in an integer array called Answer().

\\
Public Function Reduce(ByVal Numerator As Double, ByVal Denominator As
Double) As Integer
Dim Answer(2) As Integer
....
'Code here
....
Answer(1) = CInt(Numerator / b)
Answer(2) = CInt(Denominator / b)
Return Answer()
End Function
\\

(I use only Answer(1) and Answer(2) here, as Answer(0) is used for another
value elsewhere)

I'm having problems with the last line - Return Answer(). I don't know what
to put there to get it to return the entire array. Everything I put seems
to bring up red squiglies.

Here is how the function is called (in a separate class):

\\
Dim Numerator, Denominator as Integer
Dim Answer(2) as Integer
Answer(2) = Reduce(Numerator, Denominator)
\\

What do I need to Return so that I get both Answer(1) and Answer(2)?

Thanks in advance.
 
T

Tom Shelton

Nathan said:
Hello,

I have a function that reduces a fraction to lowest terms, storing the
fraction in an integer array called Answer().

\\
Public Function Reduce(ByVal Numerator As Double, ByVal Denominator As
Double) As Integer
Dim Answer(2) As Integer
...
'Code here
...
Answer(1) = CInt(Numerator / b)
Answer(2) = CInt(Denominator / b)
Return Answer()
End Function
\\

(I use only Answer(1) and Answer(2) here, as Answer(0) is used for another
value elsewhere)

I'm having problems with the last line - Return Answer(). I don't know
what
to put there to get it to return the entire array. Everything I put seems
to bring up red squiglies.

Here is how the function is called (in a separate class):

\\
Dim Numerator, Denominator as Integer
Dim Answer(2) as Integer
Answer(2) = Reduce(Numerator, Denominator)
\\

What do I need to Return so that I get both Answer(1) and Answer(2)?

Thanks in advance.

Public Function Reduce(ByVal Numerator As Double, ByVal Denominator As
Double) As Integer()
Dim Answer(2) As Integer

' Code
Return Answer
End Function

Dim Answer(2) As Integer = Reduce(Numerator, Denominator)

HTH
 
H

Herfried K. Wagner [MVP]

* "Nathan said:
I have a function that reduces a fraction to lowest terms, storing the
fraction in an integer array called Answer().

\\
Public Function Reduce(ByVal Numerator As Double, ByVal Denominator As
Double) As Integer

Use 'Integer()' as return value (notice the "(", ")").
Dim Answer(2) As Integer
...
'Code here
...
Answer(1) = CInt(Numerator / b)
Answer(2) = CInt(Denominator / b)
Return Answer()

Remove the "(", ")" at the end of 'Answer()'.
End Function
\\ [...]
What do I need to Return so that I get both Answer(1) and Answer(2)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top