How can I return multiple values from a custom function?
TIA 16 17405
You can either create an object with a bunch of properties - and you set
those properties.
You can also have ByRef parameters in your function, and return values by
setting those parameters - so they consumer of your functin can check the
values of those parameters after the function is done.
"Nikolay Petrov" <jo******@mail. bg> wrote in message
news:e4******** ******@TK2MSFTN GP11.phx.gbl... How can I return multiple values from a custom function?
TIA
Return a Structure
Friend MyFunction() as MyStructure
Dim ms as MyStructure
ms.<properties> = . . . .
Return MyStructure
End Function
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Nikolay Petrov" <jo******@mail. bg> wrote in message
news:e4******** ******@TK2MSFTN GP11.phx.gbl... How can I return multiple values from a custom function?
TIA
Hi Nikolay,
In addition to the others,
Be first sure that you needed a return value.
When it is about an object you can even use a sub
Private Sub a (byval b as whateverObject)
end sub
is the same as
Private Function a (byval b as whateverObject) as whateverObject
return b
end function
I hope this helps?
Cor
ByRef is only relevent for primitives in this respect. Passing a class to
function ByRef or ByVal would not affect the called functions ability to
change the state of the passed object.
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Marina" <so*****@nospam .com> wrote in message
news:ep******** ******@TK2MSFTN GP11.phx.gbl... You can either create an object with a bunch of properties - and you set those properties. You can also have ByRef parameters in your function, and return values by setting those parameters - so they consumer of your functin can check the values of those parameters after the function is done.
"Nikolay Petrov" <jo******@mail. bg> wrote in message news:e4******** ******@TK2MSFTN GP11.phx.gbl... How can I return multiple values from a custom function?
TIA
That is true in most cases.
However, consider this:
Dim var as Object
SomeFunction(va r)
And SomeFunction sets it's parameter to a new instance of an object. In
this particular case, if the parameter is declared ByVar, 'var' is still
Nothing after the call. If it's ByRef, 'var' will be whatever SomeFunction
set it to.
"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in message
news:Oc******** ******@TK2MSFTN GP10.phx.gbl... ByRef is only relevent for primitives in this respect. Passing a class to function ByRef or ByVal would not affect the called functions ability to change the state of the passed object.
--
OHM ( Terry Burns ) . . . One-Handed-Man . . .
"Marina" <so*****@nospam .com> wrote in message news:ep******** ******@TK2MSFTN GP11.phx.gbl... You can either create an object with a bunch of properties - and you set those properties. You can also have ByRef parameters in your function, and return values
by setting those parameters - so they consumer of your functin can check
the values of those parameters after the function is done.
"Nikolay Petrov" <jo******@mail. bg> wrote in message news:e4******** ******@TK2MSFTN GP11.phx.gbl... How can I return multiple values from a custom function?
TIA
Terry,
As Marina suggests, ByRef is required for both value & reference types, as
Nikolay wants to RETURN multiple values.
Dim s As String
Dim i As Integer
Dim p As Person
CreateStuff(s, i, p)
Public Sub CreateStuff(ByR ef sOut As String, _
ByRef iOut As Integer, _
ByRef pOut As Person)
sOut = "Hello World"
iOut = 5
pOut = New Person("Me")
End Sub
You are correct ByVal is only needed if you are only changing the state of a
passed object.
Hope this helps
Jay
"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in message
news:Oc******** ******@TK2MSFTN GP10.phx.gbl... ByRef is only relevent for primitives in this respect. Passing a class to function ByRef or ByVal would not affect the called functions ability to change the state of the passed object.
--
OHM ( Terry Burns ) . . . One-Handed-Man . . .
"Marina" <so*****@nospam .com> wrote in message news:ep******** ******@TK2MSFTN GP11.phx.gbl... You can either create an object with a bunch of properties - and you set those properties. You can also have ByRef parameters in your function, and return values
by setting those parameters - so they consumer of your functin can check
the values of those parameters after the function is done.
"Nikolay Petrov" <jo******@mail. bg> wrote in message news:e4******** ******@TK2MSFTN GP11.phx.gbl... How can I return multiple values from a custom function?
TIA
Thats not quite right. Try it out and you will see that a new object is not
created byVal.
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Marina" <so*****@nospam .com> wrote in message
news:uL******** ******@TK2MSFTN GP12.phx.gbl... That is true in most cases.
However, consider this:
Dim var as Object SomeFunction(va r)
And SomeFunction sets it's parameter to a new instance of an object. In this particular case, if the parameter is declared ByVar, 'var' is still Nothing after the call. If it's ByRef, 'var' will be whatever
SomeFunction set it to.
"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in
message news:Oc******** ******@TK2MSFTN GP10.phx.gbl... ByRef is only relevent for primitives in this respect. Passing a class
to function ByRef or ByVal would not affect the called functions ability
to change the state of the passed object.
--
OHM ( Terry Burns ) . . . One-Handed-Man . . .
"Marina" <so*****@nospam .com> wrote in message news:ep******** ******@TK2MSFTN GP11.phx.gbl... You can either create an object with a bunch of properties - and you
set those properties. You can also have ByRef parameters in your function, and return values by setting those parameters - so they consumer of your functin can check the values of those parameters after the function is done.
"Nikolay Petrov" <jo******@mail. bg> wrote in message news:e4******** ******@TK2MSFTN GP11.phx.gbl... > How can I return multiple values from a custom function? > > TIA > >
Yes, I am aware of that but he doesent says what types he is returning, so
you are assuming that they be mixed.
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Terry, As Marina suggests, ByRef is required for both value & reference types, as Nikolay wants to RETURN multiple values.
Dim s As String Dim i As Integer Dim p As Person
CreateStuff(s, i, p)
Public Sub CreateStuff(ByR ef sOut As String, _ ByRef iOut As Integer, _ ByRef pOut As Person)
sOut = "Hello World" iOut = 5 pOut = New Person("Me") End Sub
You are correct ByVal is only needed if you are only changing the state of
a passed object.
Hope this helps Jay
"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in
message news:Oc******** ******@TK2MSFTN GP10.phx.gbl... ByRef is only relevent for primitives in this respect. Passing a class
to function ByRef or ByVal would not affect the called functions ability
to change the state of the passed object.
--
OHM ( Terry Burns ) . . . One-Handed-Man . . .
"Marina" <so*****@nospam .com> wrote in message news:ep******** ******@TK2MSFTN GP11.phx.gbl... You can either create an object with a bunch of properties - and you
set those properties. You can also have ByRef parameters in your function, and return values by setting those parameters - so they consumer of your functin can check the values of those parameters after the function is done.
"Nikolay Petrov" <jo******@mail. bg> wrote in message news:e4******** ******@TK2MSFTN GP11.phx.gbl... > How can I return multiple values from a custom function? > > TIA > >
Terry,
Please reread the original question, the OP wants to return multiple values,
you need to use ByRef to return multiple values. It doesn't matter what the
type of the parameter is, you need to use ByRef to return a value through
that parameter!
Remember we are talking returning objects/values, not modifying existing
objects.
As you pointed out, you can change the state of an existing object passed
ByVal.
Hope this helps
Jay
"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in message
news:eV******** ******@TK2MSFTN GP10.phx.gbl... Yes, I am aware of that but he doesent says what types he is returning, so you are assuming that they be mixed.
--
OHM ( Terry Burns ) . . . One-Handed-Man . . .
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Terry, As Marina suggests, ByRef is required for both value & reference types,
as Nikolay wants to RETURN multiple values.
Dim s As String Dim i As Integer Dim p As Person
CreateStuff(s, i, p)
Public Sub CreateStuff(ByR ef sOut As String, _ ByRef iOut As Integer, _ ByRef pOut As Person)
sOut = "Hello World" iOut = 5 pOut = New Person("Me") End Sub
You are correct ByVal is only needed if you are only changing the state
of a passed object.
Hope this helps Jay
"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in message news:Oc******** ******@TK2MSFTN GP10.phx.gbl... ByRef is only relevent for primitives in this respect. Passing a class to function ByRef or ByVal would not affect the called functions ability to change the state of the passed object.
--
OHM ( Terry Burns ) . . . One-Handed-Man . . .
"Marina" <so*****@nospam .com> wrote in message news:ep******** ******@TK2MSFTN GP11.phx.gbl... > You can either create an object with a bunch of properties - and you set > those properties. > You can also have ByRef parameters in your function, and return
values by > setting those parameters - so they consumer of your functin can
check the > values of those parameters after the function is done. > > "Nikolay Petrov" <jo******@mail. bg> wrote in message > news:e4******** ******@TK2MSFTN GP11.phx.gbl... > > How can I return multiple values from a custom function? > > > > TIA > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Darren Dale |
last post by:
Hello,
def test(data):
i = ? This is the line I have trouble with
if i==1: return data
else: return data
a,b,c,d = test()
|
by: Oksana Yasynska |
last post by:
Hi all,
I'm running Postgres 7.2.1 and I need to return multiple row sets from plpgsql
function. I'm new in plpgsql but according documentation and everything I
could find in the mailing list I need to switch to 7.3 to get at least SETOF
rows as a result.
I can't really upgrade Postgres now. Is there is any a workaround idea to
retrieve multiple rowsets?
|
by: Jose Fernandez |
last post by:
Hello.
I'm building a web service and I get this error.
NEWS.News.CoverNews(string)': not all code paths return a value
This is the WebMethod
public SqlDataReader CoverNews(string Sport)
{
|
by: D. Shane Fowlkes |
last post by:
This may be a very basic question but it's something I've never done before.
I've looked at a couple of my favorite sites and books and can't find an
answer either. I can write a Function to return a single value. No big
deal. But I want to call a Function from another Sub and the function finds
and returns an entire db record. Using ASP.NET (VB!), how can this be done
and how can I differentiate between the fields/columns?
For...
|
by: dcassar |
last post by:
I have had a lively discussion with some coworkers and decided to get
some general feedback on an issue that I could find very little
guidance on. Why is it considered bad practice to define a public
member with a return type that is derived from System.Exception? I
understand the importance of having clean, concise code that follows
widely-accepted patterns and practices, but in this case, I find it
hard to blindly follow a standard...
| |
by: aleksandar.ristovski |
last post by:
Hello all,
I have been thinking about a possible extension to C/C++ syntax.
The current syntax allows declaring a function that returns a value:
int foo();
however, if I were to return more than one value, for example three
int-s, I would have to change my "logic" and pass the references to my
|
by: xicloid |
last post by:
I'm making a function that checks the input integer and returns the
value if it is a prime number.
If the integer is not a prime number, then the function should return
nothing.
Problem is, I don't know how to do that.
Isn't there anything like "return null"in C?
|
by: ADezii |
last post by:
The incentive for this Tip was an Article by the amazing Allen Browne - I considered it noteworthy enough to post as The Tip of the Week in this Access Forum.
Original Article by Allen Browne
Traditionally, one has always thought that Functions can only return a single value, and for the most part that was true. Ever since Access 95, we gained the new functionality, through VBA, to have Functions return an entire Structure of values. A User...
|
by: Jonathan |
last post by:
I have a SQL stored procedure for adding a new record in a transactions
table. It also has two return values: CounterID and IDKey.
I want to create a webservice that accepts the 10 input parameters and
returns the two return values.
My C# programmer here says that webservice methods can only return 1 value
per method. Is that right? Though I haven't ever created a webservice, I
would have thought that a method could return a whole lot...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |