473,516 Members | 2,889 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning an array from a function

I am sure I have had this problem before and can't remember what the fix
is...

The documentation says that an array can be returned from a function
provided you do the following:-

1. Declare the function with an explicit return type - the examples suggest
it also needs the parentheses to denote a returned array thus:

Private Function GetResultArray(RawResults as String, RequiredResultSetName
as String) as String()

2. Return the array (without parentheses) as part of the Exit Function
statement thus:

Exit Function MyTempArray

Why do I always get a syntax error on the Exit Function statement, with the
line compiler complaining it is expecting end of statement after Exit
Function?

Any help appreciated...

Regards

--Jim.
Jul 17 '05 #1
6 21035
Try having the function return a variant instead of a string()

--
Stéphane Richard
"Ada World" Webmaster
http://www.adaworld.com
"Jim SUTTON" <ji**********@bradleysutton.net> wrote in message
news:LM*****************@news-binary.blueyonder.co.uk...
I am sure I have had this problem before and can't remember what the fix
is...

The documentation says that an array can be returned from a function
provided you do the following:-

1. Declare the function with an explicit return type - the examples suggest it also needs the parentheses to denote a returned array thus:

Private Function GetResultArray(RawResults as String, RequiredResultSetName as String) as String()

2. Return the array (without parentheses) as part of the Exit Function
statement thus:

Exit Function MyTempArray

Why do I always get a syntax error on the Exit Function statement, with the line compiler complaining it is expecting end of statement after Exit
Function?

Any help appreciated...

Regards

--Jim.

Jul 17 '05 #2
OK, tried that BUT without any success - I must have missed something
somewhere else if this is working for you.

Thanks and regards

--Jim.
"Stephane Richard" <st**************@verizon.net> wrote in message
news:On******************@nwrdny01.gnilink.net...
Try having the function return a variant instead of a string()

--
Stéphane Richard
"Ada World" Webmaster
http://www.adaworld.com
"Jim SUTTON" <ji**********@bradleysutton.net> wrote in message
news:LM*****************@news-binary.blueyonder.co.uk...
I am sure I have had this problem before and can't remember what the fix
is...

The documentation says that an array can be returned from a function
provided you do the following:-

1. Declare the function with an explicit return type - the examples

suggest
it also needs the parentheses to denote a returned array thus:

Private Function GetResultArray(RawResults as String,

RequiredResultSetName
as String) as String()

2. Return the array (without parentheses) as part of the Exit Function
statement thus:

Exit Function MyTempArray

Why do I always get a syntax error on the Exit Function statement, with

the
line compiler complaining it is expecting end of statement after Exit
Function?

Any help appreciated...

Regards

--Jim.


Jul 17 '05 #3
Just send a reference to the array to a sub. For example:

Public Sub calculateData(ByRef myData)
myData(5) = 1
end sub

sub Main()
Dim myData(0 to 100) as integer
Call calculateData(ByRef myData)
Debug.print myData(5)
end sub

"Jim SUTTON" <ji**********@bradleysutton.net> wrote in message news:<LM*****************@news-binary.blueyonder.co.uk>...
I am sure I have had this problem before and can't remember what the fix
is...

The documentation says that an array can be returned from a function
provided you do the following:-

1. Declare the function with an explicit return type - the examples suggest
it also needs the parentheses to denote a returned array thus:

Private Function GetResultArray(RawResults as String, RequiredResultSetName
as String) as String()

2. Return the array (without parentheses) as part of the Exit Function
statement thus:

Exit Function MyTempArray

Why do I always get a syntax error on the Exit Function statement, with the
line compiler complaining it is expecting end of statement after Exit
Function?

Any help appreciated...

Regards

--Jim.

Jul 17 '05 #4
This seems to work OK - thanks!

Regards

--Jim.

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google.c om...
Just send a reference to the array to a sub. For example:

Public Sub calculateData(ByRef myData)
myData(5) = 1
end sub

sub Main()
Dim myData(0 to 100) as integer
Call calculateData(ByRef myData)
Debug.print myData(5)
end sub

"Jim SUTTON" <ji**********@bradleysutton.net> wrote in message

news:<LM*****************@news-binary.blueyonder.co.uk>...
I am sure I have had this problem before and can't remember what the fix
is...

The documentation says that an array can be returned from a function
provided you do the following:-

1. Declare the function with an explicit return type - the examples suggest it also needs the parentheses to denote a returned array thus:

Private Function GetResultArray(RawResults as String, RequiredResultSetName as String) as String()

2. Return the array (without parentheses) as part of the Exit Function
statement thus:

Exit Function MyTempArray

Why do I always get a syntax error on the Exit Function statement, with the line compiler complaining it is expecting end of statement after Exit
Function?

Any help appreciated...

Regards

--Jim.

Jul 17 '05 #5
Private Sub Command1_Click()

Dim x() As String

x = DoSomething("hello", "world")

Print x(0)
Print x(1)

End Sub
Private Function DoSomething(p1 As String, p2 As String) As String()

Dim buff() As String

ReDim buff(0 To 1) As String

buff(0) = p1
buff(1) = p2

DoSomething = buff

End Function

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
"Jim SUTTON" <ji**********@bradleysutton.net> wrote in message
news:LM*****************@news-binary.blueyonder.co.uk...
: I am sure I have had this problem before and can't remember what the fix
: is...
:
: The documentation says that an array can be returned from a function
: provided you do the following:-
:
: 1. Declare the function with an explicit return type - the examples
suggest
: it also needs the parentheses to denote a returned array thus:
:
: Private Function GetResultArray(RawResults as String,
RequiredResultSetName
: as String) as String()
:
: 2. Return the array (without parentheses) as part of the Exit Function
: statement thus:
:
: Exit Function MyTempArray
:
: Why do I always get a syntax error on the Exit Function statement, with
the
: line compiler complaining it is expecting end of statement after Exit
: Function?
:
: Any help appreciated...
:
: Regards
:
: --Jim.
:
:
Jul 17 '05 #6

"Jim SUTTON" <ji**********@bradleysutton.net> wrote in message
news:LM*****************@news-binary.blueyonder.co.uk...
I am sure I have had this problem before and can't remember what the fix
is...

The documentation says that an array can be returned from a function
provided you do the following:-

1. Declare the function with an explicit return type - the examples suggest
it also needs the parentheses to denote a returned array thus:

Private Function GetResultArray(RawResults as String, RequiredResultSetName
as String) as String()

2. Return the array (without parentheses) as part of the Exit Function
statement thus:

Exit Function MyTempArray

Why do I always get a syntax error on the Exit Function statement, with the
line compiler complaining it is expecting end of statement after Exit
Function?

Any help appreciated...

Regards

--Jim.

You need to exit with:
FunctionName = MyTempArray
Exit Function ' (or End Function)

I never heard of putting a return value on the same line as Exit Function.
Jul 17 '05 #7

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

Similar topics

2
5199
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it down to a very simple test case which can be cut-n-pasted into a .html file and viewed in a browser: ...
5
5461
by: shyam | last post by:
Hi All I have to write a function which basically takes in a string and returns an unknown number( at compile time) of strings i hav the following syntax in mind char *tokenize(char *) is it ok?
14
2446
by: Protoman | last post by:
How would you write a function returning a function pointer and why would you need to do this? Is it: int(*)(int&) fn(int& arg); Thanks!!!
4
14991
by: John | last post by:
Hi I need to return an array of string in my own split function (access 97). I have defined the function as below but I get err on 'As String()'. What can I do to make the function return an array of strings? Public Function Split(ByVal strIn As String, Optional strDelimiter As String = " ") As String() Thanks
2
7128
by: Tany | last post by:
How can I declare function returning array of Integer pointers . Please help !!
0
1866
by: DWalker | last post by:
VBA, as used in Excel 2000 and Excel 2003, has a function called Array. It's commonly seen in statements like the following: Workbooks.OpenText Filename:=ACFileName, _ StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 2), _ Array(9, 1), Array(18, 1), Array(33, 1), Array(49, 1), Array(71, 1), _ Array(75, 1), Array(89, 1),...
26
2697
by: MLH | last post by:
How would I modify the following to achieve a 2-dimensional array? Dim MyWeek, MyDay MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun") ' Return values assume lower bound set to 1 (using Option Base ' statement). MyDay = MyWeek(2) ' MyDay contains "Tue". MyDay = MyWeek(4) ' MyDay contains "Thu". In other words, I want the...
13
2535
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 data from a query into an array. The intent is that the following code:
9
2670
by: =?Utf-8?B?RGFya21hbg==?= | last post by:
Hi, I am wondering how you multi-dimension an array function? My declared function looks like this: Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long, ByVal Val3 As String) As String() Previously I dimensioned a single dimension Array to the size I wanted and
0
1346
ntxsoft
by: ntxsoft | last post by:
Hello everybody, I have a small problem while returning array from web service. Firstly I'm new at java web services and I'm using netbeans 6 with glassfish 2. The problem is I have a class, name is "Experience" and I want to return Experience array from service. In web service I implement like that @WebMethod(operationName = "getExperience")...
0
7276
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...
0
7408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7581
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7142
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...
1
5110
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4773
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...
0
3267
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...
0
1624
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
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.