473,398 Members | 2,380 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,398 software developers and data experts.

pass unknown number of parameters to function

ndm
Hi,

Just wondering if any one knows a way to pass and enumerate an unknown
number of parameter to a VB function. I want to create a Min/Max functions
that can:
a) take an variable number of parameters
b) determine how many parameter are passed to it
c) loop through parameters

PS. I can't use an array or collection

Any help appreciated
Neil
Nov 21 '05 #1
10 2838
Hi Neil,

I think that ParmamArray is the best answer on your question

From MSDN in the function page what is referenenced in the link bellow.
\\\
Public Function CalcSum(ByVal ParamArray Args() As Double) As Double
Dim I As Integer
CalcSum = 0
If Args.Length <= 0 Then Exit Function ' No arguments passed.
For I = 0 To UBound(Args, 1)
CalcSum += Args(I)
Next I
End Function ' Returns latest value of CalcSum.
The function can be invoked as follows:

Dim ReturnedValue As Double
ReturnedValue = CalcSum(4, 3, 2, 1)
' The function's local variables are assigned the following values:
' Args(0) = 4, Args(1) = 3, and so
on.http://msdn.microsoft.com/library/de...en-us/vblr7/ht
ml/vakeyparamarray.asp

I hope this helps?

Cor

Hi,

Just wondering if any one knows a way to pass and enumerate an unknown
number of parameter to a VB function. I want to create a Min/Max functions
that can:
a) take an variable number of parameters
b) determine how many parameter are passed to it
c) loop through parameters

PS. I can't use an array or collection

Any help appreciated
Neil

Nov 21 '05 #2
ndm
Cor,

Just what I needed, thanks a million

Neil

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O6*************@tk2msftngp13.phx.gbl...
Hi Neil,

I think that ParmamArray is the best answer on your question

From MSDN in the function page what is referenenced in the link bellow.
\\\
Public Function CalcSum(ByVal ParamArray Args() As Double) As Double
Dim I As Integer
CalcSum = 0
If Args.Length <= 0 Then Exit Function ' No arguments passed.
For I = 0 To UBound(Args, 1)
CalcSum += Args(I)
Next I
End Function ' Returns latest value of CalcSum.
The function can be invoked as follows:

Dim ReturnedValue As Double
ReturnedValue = CalcSum(4, 3, 2, 1)
' The function's local variables are assigned the following values:
' Args(0) = 4, Args(1) = 3, and so
on.http://msdn.microsoft.com/library/de...en-us/vblr7/ht ml/vakeyparamarray.asp

I hope this helps?

Cor

Hi,

Just wondering if any one knows a way to pass and enumerate an unknown
number of parameter to a VB function. I want to create a Min/Max functions that can:
a) take an variable number of parameters
b) determine how many parameter are passed to it
c) loop through parameters

PS. I can't use an array or collection

Any help appreciated
Neil


Nov 21 '05 #3
I Love this Group ;)

K.

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O6*************@tk2msftngp13.phx.gbl...
Hi Neil,

I think that ParmamArray is the best answer on your question

From MSDN in the function page what is referenenced in the link bellow.
\\\
Public Function CalcSum(ByVal ParamArray Args() As Double) As Double
Dim I As Integer
CalcSum = 0
If Args.Length <= 0 Then Exit Function ' No arguments passed.
For I = 0 To UBound(Args, 1)
CalcSum += Args(I)
Next I
End Function ' Returns latest value of CalcSum.
The function can be invoked as follows:

Dim ReturnedValue As Double
ReturnedValue = CalcSum(4, 3, 2, 1)
' The function's local variables are assigned the following values:
' Args(0) = 4, Args(1) = 3, and so
on.http://msdn.microsoft.com/library/de...en-us/vblr7/ht ml/vakeyparamarray.asp

I hope this helps?

Cor

Hi,

Just wondering if any one knows a way to pass and enumerate an unknown
number of parameter to a VB function. I want to create a Min/Max functions that can:
a) take an variable number of parameters
b) determine how many parameter are passed to it
c) loop through parameters

PS. I can't use an array or collection

Any help appreciated
Neil


Nov 21 '05 #4
* "ndm" <nm*****@northnet.com.au> scripsit:
Just wondering if any one knows a way to pass and enumerate an unknown
number of parameter to a VB function. I want to create a Min/Max functions
that can:
a) take an variable number of parameters
b) determine how many parameter are passed to it
c) loop through parameters


'ParamArray' (Visual Basic .NET)
<URL:http://msdn.microsoft.com/library/en-us/vblr7/html/vakeyParamArray.asp>

9.2.5.4 'ParamArray' Parameters (Visual Basic .NET)
<URL:http://msdn.microsoft.com/library/en-us/vbls7/html/vblrfvbspec7_1_6_4.asp>

Data passed to a method in a paramarray parameter is treated as an array
inside the method.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
Herfried,

Sometimes your echo is late however a message what is answered 5 hours
before, and where two persons answers that the answer fits, and you than and
give an extra link cannot be the purpose of a newsgroup?

When we all visitors here start answer all messages which are allready
answered, the ones who where looking for an answer on there question where
impossible to find that. (It is always possible to find an extra link you
know).

Or is it that you not on top of that list of most posters what we saw posted
yesterday, I can assure you that that list cannot the right one, you would
be on top for all the post of the last year and not Ken.

Only my thought of course to improve the quality of this newsgroup.

Cor
"> * "ndm" <nm*****@northnet.com.au> scripsit:
Just wondering if any one knows a way to pass and enumerate an unknown
number of parameter to a VB function. I want to create a Min/Max functions that can:
a) take an variable number of parameters
b) determine how many parameter are passed to it
c) loop through parameters
'ParamArray' (Visual Basic .NET)

<URL:http://msdn.microsoft.com/library/en-us/vblr7/html/vakeyParamArray.asp>
9.2.5.4 'ParamArray' Parameters (Visual Basic .NET)
<URL:http://msdn.microsoft.com/library/en...bspec7_1_6_4.a
sp>
Data passed to a method in a paramarray parameter is treated as an array
inside the method.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
* "Cor Ligthert" <no**********@planet.nl> scripsit:
Sometimes your echo is late however a message what is answered 5 hours
before, and where two persons answers that the answer fits, and you than and
give an extra link cannot be the purpose of a newsgroup?


I didn't see the links in your post and I think that they are important
in addition to your answer.

Just my 2 Euro cents...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7
Herfried,
I didn't see the links in your post and I think that they are important
in addition to your answer.


I thought that it was that, however sometimes it can be overdone.

The links was not right in my post and I had seen that long before you,
however I have seen so many links which where real much worse, it could be
easy be copied and pasted, therefore I did not correct it this time.

However this kind of messages are to learn for us, and as forever only to
improve our quality.

That interface post was great, a pity you did not answer my message in that.

Cor
Nov 21 '05 #8
It's not worth pursuing this point Cor, because its been brought up many
times before and H Continues to do this. My belief ( Although he will deny
this as he has done in the past ) is that he thinks that by having the most
posts he can secure another MVP year.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Herfried,

Sometimes your echo is late however a message what is answered 5 hours
before, and where two persons answers that the answer fits, and you than and give an extra link cannot be the purpose of a newsgroup?

When we all visitors here start answer all messages which are allready
answered, the ones who where looking for an answer on there question where
impossible to find that. (It is always possible to find an extra link you
know).

Or is it that you not on top of that list of most posters what we saw posted yesterday, I can assure you that that list cannot the right one, you would
be on top for all the post of the last year and not Ken.

Only my thought of course to improve the quality of this newsgroup.

Cor
"> * "ndm" <nm*****@northnet.com.au> scripsit:
Just wondering if any one knows a way to pass and enumerate an unknown
number of parameter to a VB function. I want to create a Min/Max functions that can:
a) take an variable number of parameters
b) determine how many parameter are passed to it
c) loop through parameters
'ParamArray' (Visual Basic .NET)

<URL:http://msdn.microsoft.com/library/en-us/vblr7/html/vakeyParamArray.asp>

9.2.5.4 'ParamArray' Parameters (Visual Basic .NET)

<URL:http://msdn.microsoft.com/library/en...bspec7_1_6_4.a sp>

Data passed to a method in a paramarray parameter is treated as an array
inside the method.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #9
* "Cor Ligthert" <no**********@planet.nl> scripsit:
I didn't see the links in your post and I think that they are important
in addition to your answer.


I thought that it was that, however sometimes it can be overdone.


It's not overdone in my opinion.

It's not me, and its not you who define what's "overdone" in this group
and what's not, and what's helpful and what is not helpful. Threads are
here to answer the OP's question, but they are also here to collect
information on a certain topic to make it easier for people to find the
answers in future.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #10
Herfried,
I didn't see the links in your post and I think that they are important
in addition to your answer.


I thought that it was that, however sometimes it can be overdone.


It's not overdone in my opinion.

It's not me, who define what's "overdone" in this group


(I removed "and not you")

LOL

Cor
Nov 21 '05 #11

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

Similar topics

1
by: lawrence | last post by:
The following class method is being rejected by the PHP parser. If I change the method paramaters and allow the objects to be passed as copies, then the parser has no problem. Or, if I pass by...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
0
by: Zlatko Matić | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
10
by: nospam | last post by:
Hello! I can pass a "pointer to a double" to a function that accepts double*, like this: int func(double* var) { *var=1.0; ... }
9
by: Christian Christmann | last post by:
Hi, I was just going through this exercise http://www.cas.mcmaster.ca/~franek/books/membook-answers/ch4/answers-ch4-3.html and I'am confused about the answer. It says: "... the compiler...
12
by: ArunDhaJ | last post by:
Hi Friends, Is it possible to pass a table as a parameter to a funtion. whos function declaration would look some thing like this.... ALTER FUNCTION TempFunction (@TempTable TABLE, @nPId INT) ...
1
by: devid33 | last post by:
#!/usr/bin/perl use Getopt::Long; $l=@ARGV; print "The number of args is " . @ARGV;print "\n";
1
by: marjipie | last post by:
Hi, My problem goes like this, i created a wrapper for a third party DLL, and one of the functions is: 6.1.5.4 GetUsbDevicesNameEnum PROTOTYPE I C_MORPHO_Device::GetUsbDevicesNameEnum ( UL...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
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
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...
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
agi2029
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,...
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.