473,760 Members | 10,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

send array to a function

hi all.
i'm looking for a simple example of how to pass
optionaly, an array to a function.
if the array isn't there (it's optional) i want to know
about it.
thanks.
Nov 21 '05 #1
4 1922

Shachar

Is the parameterarray not more what you mean?

http://groups.google.com/groups?selm...tngp13.phx.gbl

I hope tis helps?

Cor
"shachar"
hi all.
i'm looking for a simple example of how to pass
optionaly, an array to a function.
if the array isn't there (it's optional) i want to know
about it.
thanks.

Nov 21 '05 #2
Shachar,
In addition to ParamArray as Cor suggested.

I would consider Overloading the function or using the Optional keyword.

For example:

' 1. (a) Overload Sum to take 0 parameters
Private Function Sum() As Integer
Return 0
End Function

' 1. (b) Overload Sum to take an array of parameters.
Private Function Sum(ByVal list() As Integer) As Integer
Dim total As Integer
For Each item As Integer In list
total += item
Next
Return total
End Function

' 2. An Optional parameter
Private Function Sum(Optional ByVal list() As Integer = Nothing) As
Integer
If list Is Nothing Then Return 0
Dim total As Integer
For Each item As Integer In list
total += item
Next
Return total
End Function

' 3. An ParamArray
Private Function Sum(ByVal ParamArray list() As Integer) As Integer
Dim total As Integer
For Each item As Integer In list
total += item
Next
Return total
End Function
1, 2 & 3 allow the following:

Dim total As Integer
Dim list() As Integer
total = Sum()
total = Sum(list)

In the above case I prefer 1 as I am letting the compiler decide if I passed
the parameter or not, where as in 2 I have a runtime check to decide if the
parameter was passed or not. 2 will have problems if I can legitimately pass
Nothing as a value for list.

3 also allows:

total = Sum(1,2,3,4,5,6 )

I normally use 1 or 3 depending on if I wanted a list of values inline on
the call, rather then explicitly create an array. Depending on what I am
creating I will combine 1 with 3, where I overload on 0, 1, 2, 3 fixed
parameters, then have a ParamArray overload. Similar to the overloads on
String.Format.

Hope this helps
Jay
"shachar" <an*******@disc ussions.microso ft.com> wrote in message
news:2f******** *************** *****@phx.gbl.. .
hi all.
i'm looking for a simple example of how to pass
optionaly, an array to a function.
if the array isn't there (it's optional) i want to know
about it.
thanks.

Nov 21 '05 #3
can you show me an example of how to get an array
optionaly into a function.
** i must get an array() .
thanks.
-----Original Message-----
Shachar,
In addition to ParamArray as Cor suggested.

I would consider Overloading the function or using the Optional keyword.
For example:

' 1. (a) Overload Sum to take 0 parameters
Private Function Sum() As Integer
Return 0
End Function

' 1. (b) Overload Sum to take an array of parameters.
Private Function Sum(ByVal list() As Integer) As Integer Dim total As Integer
For Each item As Integer In list
total += item
Next
Return total
End Function

' 2. An Optional parameter
Private Function Sum(Optional ByVal list() As Integer = Nothing) AsInteger
If list Is Nothing Then Return 0
Dim total As Integer
For Each item As Integer In list
total += item
Next
Return total
End Function

' 3. An ParamArray
Private Function Sum(ByVal ParamArray list() As Integer) As Integer Dim total As Integer
For Each item As Integer In list
total += item
Next
Return total
End Function
1, 2 & 3 allow the following:

Dim total As Integer
Dim list() As Integer
total = Sum()
total = Sum(list)

In the above case I prefer 1 as I am letting the compiler decide if I passedthe parameter or not, where as in 2 I have a runtime check to decide if theparameter was passed or not. 2 will have problems if I can legitimately passNothing as a value for list.

3 also allows:

total = Sum(1,2,3,4,5,6 )

I normally use 1 or 3 depending on if I wanted a list of values inline onthe call, rather then explicitly create an array. Depending on what I amcreating I will combine 1 with 3, where I overload on 0, 1, 2, 3 fixedparameters, then have a ParamArray overload. Similar to the overloads onString.Forma t.

Hope this helps
Jay
"shachar" <an*******@disc ussions.microso ft.com> wrote in messagenews:2f******* *************** ******@phx.gbl. ..
hi all.
i'm looking for a simple example of how to pass
optionaly, an array to a function.
if the array isn't there (it's optional) i want to know
about it.
thanks.

.

Nov 21 '05 #4
Shachar,
I believe I did!

Did you look at the samples I gave, did you try the samples I gave. Did you
try changing one of the samples to the type you want?

Did you try "As Array" instead of "As Integer"?

Can you better explain what you want?

Hope this helps
Jay
"shachar" <an*******@disc ussions.microso ft.com> wrote in message
news:08******** *************** *****@phx.gbl.. .
can you show me an example of how to get an array
optionaly into a function.
** i must get an array() .
thanks.
-----Original Message-----
Shachar,
In addition to ParamArray as Cor suggested.

I would consider Overloading the function or using the

Optional keyword.

For example:

' 1. (a) Overload Sum to take 0 parameters
Private Function Sum() As Integer
Return 0
End Function

' 1. (b) Overload Sum to take an array of parameters.
Private Function Sum(ByVal list() As Integer) As

Integer
Dim total As Integer
For Each item As Integer In list
total += item
Next
Return total
End Function

' 2. An Optional parameter
Private Function Sum(Optional ByVal list() As

Integer = Nothing) As
Integer
If list Is Nothing Then Return 0
Dim total As Integer
For Each item As Integer In list
total += item
Next
Return total
End Function

' 3. An ParamArray
Private Function Sum(ByVal ParamArray list() As

Integer) As Integer
Dim total As Integer
For Each item As Integer In list
total += item
Next
Return total
End Function
1, 2 & 3 allow the following:

Dim total As Integer
Dim list() As Integer
total = Sum()
total = Sum(list)

In the above case I prefer 1 as I am letting the

compiler decide if I passed
the parameter or not, where as in 2 I have a runtime

check to decide if the
parameter was passed or not. 2 will have problems if I

can legitimately pass
Nothing as a value for list.

3 also allows:

total = Sum(1,2,3,4,5,6 )

I normally use 1 or 3 depending on if I wanted a list of

values inline on
the call, rather then explicitly create an array.

Depending on what I am
creating I will combine 1 with 3, where I overload on 0,

1, 2, 3 fixed
parameters, then have a ParamArray overload. Similar to

the overloads on
String.Format .

Hope this helps
Jay
"shachar" <an*******@disc ussions.microso ft.com> wrote in

message
news:2f****** *************** *******@phx.gbl ...
hi all.
i'm looking for a simple example of how to pass
optionaly, an array to a function.
if the array isn't there (it's optional) i want to know
about it.
thanks.

.

Nov 21 '05 #5

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

Similar topics

10
32651
by: BadOmen | last post by:
I want my program to send a mouse click to the window at the current mouse position, how do I do that? Example: I have my mouse over a button in Word and then my program is sending the left mouse click and the button under the mouse is clicked. Yours, Jonas
6
1811
by: simon | last post by:
Always when I need data reader in my programs, I simply have functions, which creates it for me: Dim rdr As SqlDataReader dim sql as string sql="myStoredProcedure" rdr = createDataReader(sql, False) And the functions are:
12
5992
by: Uncle | last post by:
I am an untrained hobbyist. Everything about programming I have learned from the internet. Thank you all for your gracious support. This is what I have: #define CONST_CHAR 0 void some_func( char* arg, int len ) { // stuff }
6
2459
by: druidamix | last post by:
I'm trying to make a gui for an application, but it not run. i'm trying to send the output of execlp to pipe and read from his father. but i don't obtain results. Any advince? Thank you. This is the code:
2
36717
Plater
by: Plater | last post by:
I am using the XMLHttpRequest to send a request every 5ish seconds or so. Everything works fine until I take the server down that the object is trying to retrieve data from. Then the firefox console keeps racking up these: uncaught exception: " nsresult: "0x80004005 (NS_ERROR_FAILURE)" If I turn the server back on, it continues to update it's data just fine. I know a simple solution is to just trap the exception, but I don't think I...
1
1737
by: everlives | last post by:
Hello Please help me any one. i am trying to send variable from scroll pane in Flash 8 to PHP But i am not getting the value "undefined": the code as follows: // create an xml object to hold the gigs
1
6857
by: maxxxxel | last post by:
Hi Can anyone help me with some asp code , I changed the code to use CDO.message instead of the old cdont.sys to send mail from a ASP webpage which works fine. Our problem is that when we send mail externally to a internet email site like Gmail the PDF is sent but is corrupted because CDOSYS ends up using binary encoding rather than Base64 encoding when creating the attachment. More information here: Anthonys Code My knowledge of ASP...
3
1316
by: harry.viet | last post by:
I use the prototype library and create a class that builds a grid using some parameters as mentioned below. Everything is working but only the parameters for Number formatting var gridopts = { iPageSize : 100, dataSource : '../data/ledgergetdata.asp', dataPars : { acct_type : '2' }, columns : }, { name: 'credit', field : 'credit', width: '10%' ,
0
9521
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9333
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,...
0
8768
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, 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...
0
6599
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();...
0
5214
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...
0
5361
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3863
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3442
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2733
bsmnconsultancy
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...

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.