Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / January 2006

Tip: Looking for answers? Try searching our database.

Function returning array of strings

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 29 Jan 2006 09:59 GMT
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
RoyVidar - 29 Jan 2006 10:28 GMT
John wrote in message <O5cEArLJGHA.208@tk2msftngp13.phx.gbl> :
> Hi
>
[quoted text clipped - 8 lines]
>
> 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_strInString) > 0 Then
       lngStart = 1
       Do
           lngStop = InStr(lngStart, v_strInString, v_strDelimiter)
           If lngStop = 0 Then Exit Do
           ReDim Preserve varResult(lngCounter)
           varResult(lngCounter) = _
                     Mid$(v_strInString, lngStart, lngStop - lngStart)
           lngCounter = lngCounter + 1
           lngStart = lngStop + Len(v_strDelimiter)
       Loop
       ReDim Preserve varResult(lngCounter)
       varResult(lngCounter) = Mid$(v_strInString, lngStart)
   Else
       rvsSplit = Array()
   End If
   rvsSplit = varResult

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

Signature

Roy-Vidar

Wayne Gillespie - 29 Jan 2006 10:34 GMT
>Hi
>
[quoted text clipped - 8 lines]
>
>Regards

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

Wayne Gillespie
Gosford NSW Australia
Wayne Gillespie - 29 Jan 2006 10:37 GMT
>>Hi
>>
[quoted text clipped - 11 lines]
>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
Douglas J. Steele - 29 Jan 2006 12:10 GMT
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(varReturn) To UBound(varReturn)
       Debug.Print intLoop & ": " & varReturn(intLoop)
   Next intLoop

End Sub

In the Immediate window:

CallArray
1: One
2: Two
3: Three

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

> Hi
>
[quoted text clipped - 8 lines]
>
> Regards
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.