[AccessD] Determine the number of columns in an array

Mark H lists at theopg.com
Fri Jul 4 02:56:00 CDT 2003


Thanks Stuart... Nice solution.

Thanks also to Andy and Jim - sorry, I worded my email badly. I was
actually looking for the number of dimensions (see below)

Thanks again

Mark

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart
McLachlan
Sent: 03 July 2003 23:09
To: Mark H; accessd at databaseadvisors.com
Subject: Re: [AccessD] Determine the number of columns in an array


On 3 Jul 2003 at 16:32, Mark H wrote:

> Hello all...
> 
> Sorry if this is a bit simple, but I'm in a bit of a rush to get out 
> and wanted to ask before I go (climbing - yippeeee)...
> 
> Anyway, does anyone know how to determine the number of columns in an 
> array? I am trying to write a bit of generic code and want to be able 
> to pass the array and then figure out its width. I looked in the helps

> "See also" under Lbound and Ubound but found nothing...
> 

Not that simple :-( .  
This is the first  working solution I can think of, hopefully someone 
has something more elegant. It just keeps on trying to get the 
UBOUND() of successive dimensions until it errors out with a 
"Subscript out of range".

Function Dimensions(ArrayName As Variant) As Long
    Dim dimcount As Long
    Dim result As Long
    If Not IsArray(ArrayName) Then
        MsgBox "Not an Array"
        Exit Function
    End If
    On Error GoTo errtrap
    Do
     dimcount = dimcount + 1
     result = UBound(ArrayName, dimcount)
    Loop
    On Error GoTo 0
    Exit Function
errtrap:
    If Err = 9 Then
     Dimensions = dimcount - 1
     Exit Function
    Else
       MsgBox "Error " & Err.Number & ": " & Err.Description & " in 
Function Dimensions()"
    End If
End Function

Function test() As Long
    Dim testarray(3, 4, 5, 6, 7, 8, 9) As String
    test = Dimensions(testarray)
End Function



-- 
Lexacorp Ltd
http://www.lexacorp.com.pg
Information Technology Consultancy, Software Development,System 
Support.



_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list