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