Wrox Programmer Forums
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 2nd, 2005, 07:55 PM
Registered User
 
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multi returning function

dear all

how can i build a function that can return 3 values...

for e.g.

public function r3v(xx as integer, yy as integer)as integer

r3v=yy
r3v=xx

end function

hom can i????








 
Old March 3rd, 2005, 06:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You could return an array:

public function r3v(xx as integer, yy as integer)as integer()
   Dim x(2) As Integer

   x(0) = yy
   x(1) = xx
   x(2) = yy+xx

   r3v = x
End Function

then you call it like this:

Dim ReturnArray() As Integer
ReturnArray() = c3v(99, 100)
For i = 0 To Ubound(ReturnArray)
    Debug.Print ReturnArray(i)
Next

Or you could just add extra ByRef parameters to your function and modify them inside the function.
 
Old March 3rd, 2005, 01:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

instead of a function, create a method and declare the output variables byRef

public/private sub MySub(byval in1, byval in2,... byref out1, byref out2,...)

all the byval (by value) are [in] parameters (that is, they cannot be changed inside MySub, actually they can but when the sub returns they are left the same), and all the byref (by reference) are [out] parameters that can be modified

Marco





Similar Threads
Thread Thread Starter Forum Replies Last Post
Function returning an array rfstuck Pro VB 6 5 March 12th, 2008 07:35 AM
Function not returning value civa Access 5 January 17th, 2006 03:44 AM
EXEC function not returning values aingalsbe PHP How-To 0 June 1st, 2004 10:03 AM
Function not returning anything... goatboy Beginning PHP 2 December 1st, 2003 12:34 PM
Returning variables from a function starsol Beginning PHP 1 September 11th, 2003 12:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.