473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Function returning an array

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.
Nov 20 '05 #1
3 1445
"Nathan" <nk*********************@softhome.net> wrote in message
news:e%****************@TK2MSFTNGP09.phx.gbl...
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
--
Tom Shelton
[MVP - Visual Basic]
Nov 20 '05 #2
* "Nathan" <nk*********************@softhome.net> scripsit:
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)?


--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Aaaah, that works. Thanks a million.
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Krackers | last post by:
How do you write a function which returns a reference to an array. I can only get a function to return a copy of the array itself. I've had a look at some other threads in this group an the return...
41
by: Materialised | last post by:
I am writing a simple function to initialise 3 variables to pesudo random numbers. I have a function which is as follows int randomise( int x, int y, intz) { srand((unsigned)time(NULL)); x...
1
by: Guha | last post by:
I have a problem with returning a 2D array using a function which is called in main(). The piece of the code is given below. This is a test code only. #include"stdio.h" #include"alloc.h" ...
2
by: Tany | last post by:
How can I declare function returning array of Integer pointers . Please help !!
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
1
by: vijay.gandhi | last post by:
Hello, I have created a function in C++/CLI which was exported as a .DLL to be used in VB .NET. I have been having some problems (I think it has to do with the right syntax) with parameter...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
13
by: Sri Harsha Dandibhotla | last post by:
Hello all. I recently came across a function declaration as : char(*(*x()))(); This was not in some code but it was in a C questions thread on some group. I tried to decipher what it returns but...
160
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
5
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.