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

Returning an array from a function?

I'm currently using the following function to return an ArrayList:

Private Function ADSIReturnComputers(ByVal BldgMnemonic As String) As
ArrayList
Dim x As New ArrayList

Using oDirectoryEntry As DirectoryEntry = New
DirectoryEntry("LDAP://us.ups.com")
Using oDirectorySearcher As DirectorySearcher = New
DirectorySearcher(oDirectoryEntry)

oDirectorySearcher.Filter =
"(&(ObjectClass=Computer)(cn=" & BldgMnemonic & "*))"

For Each oResult As SearchResult In
oDirectorySearcher.FindAll
x.Add(oResult.GetDirectoryEntry.Name)
Next

End Using
End Using

Return x
End Function

Is there an easy way to return just a static array of string? Or would
that be more work than it's worth?
*** Sent via Developersdex http://www.developersdex.com ***
Aug 29 '06 #1
3 1028
Terry,

Your question can be confusing, do you mean return a "static" arraylist as
it is in the context of Visual Basis inside a method?

Than you should pass that in my idea that arraylist just byval to the
method.

Cor

"Terry Olsen" <to******@hotmail.comschreef in bericht
news:eY**************@TK2MSFTNGP04.phx.gbl...
I'm currently using the following function to return an ArrayList:

Private Function ADSIReturnComputers(ByVal BldgMnemonic As String) As
ArrayList
Dim x As New ArrayList

Using oDirectoryEntry As DirectoryEntry = New
DirectoryEntry("LDAP://us.ups.com")
Using oDirectorySearcher As DirectorySearcher = New
DirectorySearcher(oDirectoryEntry)

oDirectorySearcher.Filter =
"(&(ObjectClass=Computer)(cn=" & BldgMnemonic & "*))"

For Each oResult As SearchResult In
oDirectorySearcher.FindAll
x.Add(oResult.GetDirectoryEntry.Name)
Next

End Using
End Using

Return x
End Function

Is there an easy way to return just a static array of string? Or would
that be more work than it's worth?
*** Sent via Developersdex http://www.developersdex.com ***

Aug 29 '06 #2
>Is there an easy way to return just a static array of string? Or would
that be more work than it's worth?
Return CType(x.ToArray(GetType(String)), String())
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Aug 29 '06 #3
Return CType(x.ToArray(GetType(String)), String())

Or more simply,

Dim x As New List(Of String)
....
Return x.ToArray()

-h-
Aug 29 '06 #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...
7
by: BrianJones | last post by:
Hi, if you have a function, how is it possible to return an array? E.g.: unsigned long function(...) // what I want to do, obviously illegal I do know such would be possible by using a dynamic...
5
by: Gent | last post by:
I have two questions which are very similar: Is it possible to return an object in C++. Below is part of my code for reference however I am more concerned about the concept. It seems like the...
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...
10
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences...
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: ...
13
by: Karl Groves | last post by:
I'm missing something very obvious, but it is getting late and I've stared at it too long. TIA for responses I am writing a basic function (listed at the bottom of this post) that returns...
0
by: anuptosh | last post by:
Hi, I have been trying to run the below example to get a Oracle Array as an output from a Java code. This is an example I have found on the web. But, the expected result is that the code should...
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
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:
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
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
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.