By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,573 Members | 3,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,573 IT Pros & Developers. It's quick & easy.

Array error when passing to Sub

P: n/a
I'm trying to implement a sorting routine for a string array. The sort
routine is from http://ourworld.compuserve.com/homep...cg/acgsoft.htm
(a great selection of routines in the 'Sequence Dancing' application),
and I thought it would be easy to use.

I am looping through a collection of tables and extracting the field
names. These are then populated in a list box, to allow users to
include custom fields in a data query. The fields are appended into a
string list, and then the SPLIT() function is used to create an array.
The array is passed to the sorting routine (here the error occurs),
and then the JOIN() function is used to return the sorted values to a
list for the listbox rowsource.

The error is "Type Mismatch: Array or user defined type expected".

Help would be appreciated.

Function GetFields(strTableName As String)
On Error GoTo Err_Tag

Dim db As DAO.Database
Dim td As DAO.TableDef
Dim fld As DAO.Field
Dim strFields, strLimitList As String
Dim arrFields() As String

strLimitList = "STATION_NO,LATITUDE,LONGITUDE,SAMPLE_NO,SAMPLE_TI ME,VALUE,FLAG,QCFLAG"

Set db = CurrentDb
For Each td In db.TableDefs
If InStr(strTableName, td.Name) Then
For Each fld In td.Fields
If InStr(strLimitList, fld.Name) = False Then
If strFields = "" Then
strFields = fld.Name
Else
strFields = strFields & "," & fld.Name
End If
End If
Next
End If
Next

arrFields = Split(strFields, ",")

'Sort the Array
strExchangeSort (arrFields) <-------------- error occurs here
' Recreate the String for the List
GetFields = Join(arrFields, ",")

Exit_Tag:
Exit Function

Err_Tag:
MsgBox Err.Description
Resume Exit_Tag

End Function
Sub strExchangeSort(pstrItem() As String)

' strExchangeSort compares each element - starting
' with the 1st element - with every following element.
' If any of the elements is less than the current element,
' it is exchanged with the current element and the process
' is repeated for the next element.
'
Dim intRow As Integer, intSmallestRow As Integer, intJ As Integer,
intLastItem As Integer
'
intLastItem = UBound(pstrItem)
For intRow = 1 To intLastItem
intSmallestRow = intRow
For intJ = intRow + 1 To intLastItem
If pstrItem(intJ) < pstrItem(intSmallestRow) Then
intSmallestRow = intJ
End If
Next
'
If intSmallestRow > intRow Then
SwapStr pstrItem(), intRow, intSmallestRow
End If
Next

End Sub

Sub SwapStr(pstrItem() As String, ByVal pintRow1 As Integer, ByVal
pintRow2 As Integer)

' Swaps two elements of pstrItem()
'
' Called from all sort routines except strInsertSort
'
Dim strTemp As String
'
strTemp = pstrItem(pintRow1)
pstrItem(pintRow1) = pstrItem(pintRow2)
pstrItem(pintRow2) = strTemp

End Sub
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
> arrFields = Split(strFields, ",")

'Sort the Array
strExchangeSort (arrFields) <-------------- error occurs here

try strExchangeSort arrFields

(no parens with a subroutine call)
Nov 13 '05 #2

P: n/a
or
call strExchangeSort(arrFields)
--
Terry Kreft
MVP Microsoft Access
"Pieter Linden" <pi********@hotmail.com> wrote in message
news:bf**************************@posting.google.c om...
arrFields = Split(strFields, ",")

'Sort the Array
strExchangeSort (arrFields) <-------------- error occurs here

try strExchangeSort arrFields

(no parens with a subroutine call)

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.