473,729 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function returning array of strings

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

Regards
Jan 29 '06 #1
4 15000
John wrote in message <O5************ *@tk2msftngp13. phx.gbl> :
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

Regards


Yes, I'm afraid that returning arrays from functions, as far as I've
understood, is a feature included in later versions (2000 and later).

In a97, I think one will need to return a variant.

Here's a function I wrote/adapted some time ago, which can perhaps be a
starting point. I wrote this for a specific purpose, so I don't know
whether it will deal with all possible variations. For instance, it
will
not accept Null (string declaration) ...

Public Function rvsSplit(ByVal v_strInString As String, _
Optional ByVal v_strDelimiter As String = "|")
As Variant
' royvidar
' created 2005-03-09
' purpose: split a string into a variant array for processing
' In this setting, I relax a little on testing, as I'll
' only pass string variables. Use variant and add a test
' with the IsMissing function to use in other context
' parameters:
' v_strInString - string containing text with delimiter
' i e - string to be split
' v_strDelimiter - the delimiter to use in the split
' returns: variant array

Dim lngCounter As Long ' count number of delimiters to redim
array
Dim lngStart As Long ' start position of string to extract
Dim lngStop As Long ' end postition of string to extract
Dim varResult() ' variant array assigned as return value

On Error GoTo rvsSplit_Err

If Len(v_strInStri ng) > 0 Then
lngStart = 1
Do
lngStop = InStr(lngStart, v_strInString, v_strDelimiter)
If lngStop = 0 Then Exit Do
ReDim Preserve varResult(lngCo unter)
varResult(lngCo unter) = _
Mid$(v_strInStr ing, lngStart, lngStop - lngStart)
lngCounter = lngCounter + 1
lngStart = lngStop + Len(v_strDelimi ter)
Loop
ReDim Preserve varResult(lngCo unter)
varResult(lngCo unter) = Mid$(v_strInStr ing, lngStart)
Else
rvsSplit = Array()
End If
rvsSplit = varResult

rvsSplit_Exit:
Exit Function
rvsSplit_Err:
rvsSplit = vbNullString
Resume rvsSplit_Exit
End Function

--
Roy-Vidar
Jan 29 '06 #2
On Sun, 29 Jan 2006 09:59:48 -0000, "John" <Jo**@nospam.in fovis.co.uk> wrote:
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

Regards


Remove the () after As String.
Public Function Split(ByVal strIn As String, Optional strDelimiter As String = " ") As String
Wayne Gillespie
Gosford NSW Australia
Jan 29 '06 #3
On Sun, 29 Jan 2006 10:34:17 GMT, Wayne Gillespie <be*****@NOhotm ailSPAM.com.au> wrote:
On Sun, 29 Jan 2006 09:59:48 -0000, "John" <Jo**@nospam.in fovis.co.uk> wrote:
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

Regards


Remove the () after As String.
Public Function Split(ByVal strIn As String, Optional strDelimiter As String = " ") As String

Forget that. I misread the part about returning a string array. As Roy says this isn't possible in A97 AFAIK.
Wayne Gillespie
Gosford NSW Australia
Jan 29 '06 #4
As the others have indicated, Access 97 doesn't let you return a string
array, but you can pass an array as a variant without any problems.

I just tested the following code in Access 97:

Function ReturnArray() As Variant

Dim strArray(1 To 3) As String

strArray(1) = "One"
strArray(2) = "Two"
strArray(3) = "Three"

ReturnArray = strArray

End Function

Sub CallArray()

Dim intLoop As Integer
Dim varReturn As Variant

varReturn = ReturnArray()
For intLoop = LBound(varRetur n) To UBound(varRetur n)
Debug.Print intLoop & ": " & varReturn(intLo op)
Next intLoop

End Sub

In the Immediate window:

CallArray
1: One
2: Two
3: Three

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
"John" <Jo**@nospam.in fovis.co.uk> wrote in message
news:O5******** *****@tk2msftng p13.phx.gbl...
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

Regards

Jan 29 '06 #5

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

Similar topics

8
29062
by: Tweaxor | last post by:
Hey, I was trying to figure out was it possible in C to pass the values in an array from one function to another function. Is the possible in C? ex. y is the array that holds seven values If possible how could one pass these seven values in the array to a function that would check the values. I tried return y but it didn't work
5
2257
by: damian birchler | last post by:
What's wrong about this: 22: static void (*)(void) instruction_table = { jnz, halt, mv, add, mul, mv_reg, add_reg,
4
40883
by: Woody Splawn | last post by:
How would I pass an array back to a sub routine from a function? That is, I have a function that looks like this Public Function arrayTest() As Array Dim states() As String = { _ "AZ", "CA", "WA" _ } Return states End Function
5
5479
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?
18
2350
by: svata | last post by:
Hello to all, as a result from my previous post I'm busy with splitting code into functions. The one problem ( out of many ) I encounter is how to properly use/code a function which returns either array of characters(string) or a pointer to this array. I read some articles, some other posts and come to this solution:
20
8989
by: Andrew Morton | last post by:
Is it possible to have two function declarations which take the same parameters but return different types depending on how the function is used? function f(x) as string ' return a string end function function f(x) as string() ' return an array of strings end function
8
1790
by: jodleren | last post by:
Hi! I have a function, a part of my code which I can use as a function. It will return 2 arrays, and I am wondering what way to do so. Both arrays hold strings, there are no special keys. 1) setting the arrays as globals 2) returnin an array of arrays 3) returning a large array with a known marker to indicate when the 2nd part starts.
26
4872
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure about the syntax of calling the same. #include <stdio.h> void fp1()
13
1986
by: Sri Harsha Dandibhotla | last post by:
Hello all. I recently came across a function declaration as : char(*(*x()))(); This was not in some code but it was in a C questions thread on some group. I tried to decipher what it returns but couldn't make complete sense out of it. Can someone please explain what this function is supposed to return and expand it step by step. Thanks,
0
8921
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
9284
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9202
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,...
0
9148
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
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
4796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
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
2165
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.