CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 1999
    Location
    Switzerland
    Posts
    398

    Get array dimension?

    I pass an multi-dimensional array as variant to a method. The array can have different dimensions.
    How can I get the number of dimensions of this multi-dimensional array variable?


    Leica Geosystems - when it has to be right

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Get array dimension?

    This is just an example. You can improve it for your purpouse.
    Public Function MArrayServer_fnctTestArrayInVariant(ByVal avntTest As Variant) As Integer
    '********************************************************
    'Receive variant and test to find out if is array.
    'values back:
    ' 0 = not array/not dimensioned
    ' 1 = array monodimension
    ' 2 = array bidimension
    ' 3 = array tridimension
    ' 4 = array monodimension with an array monodimension inside
    ' 5 = array monodimension with array bidimension inside
    ' 6 = array monodimension with array tridimension inside
    ' 7 = array bidimension with array monodimension inside
    ' 8 = array bidimension with array bidimension inside
    ' 9 = array bidimension with array tridimension inside
    '10 = array tridimension with an array monodimension inside
    '11 = array tridimension with an array bidimension inside
    '12 = array tridimension with array tridimension inside

    '********************************************************
    'Dim blnSkippa As Boolean
    Dim vntPassa As Variant
    Dim OkArray As Integer
    On Error GoTo ErrHandler

    1 vntPassa = avntTest(0)
    'if ok, test for inside
    2 OkArray = 1
    Test4:
    10 vntPassa = avntTest(0)(0)
    11 MArrayServer_fnctTestArrayInVariant = 4
    12 Exit Function

    Test5:
    13 vntPassa = avntTest(0)(0, 0)
    14 MArrayServer_fnctTestArrayInVariant = 5
    15 Exit Function

    Test6:
    16 vntPassa = avntTest(0)(0, 0, 0)
    17 MArrayServer_fnctTestArrayInVariant = 6
    18 Exit Function


    Test2:
    4 vntPassa = avntTest(0, 0)
    5 OkArray = 2

    Test7:
    19 vntPassa = avntTest(0, 0)(0)
    20 MArrayServer_fnctTestArrayInVariant = 7
    21 Exit Function

    Test8:
    22 vntPassa = avntTest(0, 0)(0, 0)
    23 MArrayServer_fnctTestArrayInVariant = 8
    24 Exit Function

    Test9:
    25 vntPassa = avntTest(0, 0)(0, 0, 0)
    26 MArrayServer_fnctTestArrayInVariant = 9
    27 Exit Function


    Test3:
    7 vntPassa = avntTest(0, 0, 0)
    8 OkArray = 3

    Test10:
    28 vntPassa = avntTest(0, 0, 0)(0)
    29 MArrayServer_fnctTestArrayInVariant = 10
    30 Exit Function

    Test11:
    31 vntPassa = avntTest(0, 0, 0)(0, 0)
    32 MArrayServer_fnctTestArrayInVariant = 11
    33 Exit Function

    Test12:
    34 vntPassa = avntTest(0, 0, 0)(0, 0, 0)
    35 MArrayServer_fnctTestArrayInVariant = 12
    36 Exit Function

    Exit_1:
    MArrayServer_fnctTestArrayInVariant = OkArray

    eXit_fUnction:


    Exit Function

    ErrHandler:
    Select Case Err
    Case 9
    Select Case Erl
    Case 1
    Resume Test2
    Case 4
    Resume Test3
    Case 7
    MArrayServer_fnctTestArrayInVariant = 0
    Case 10
    Resume Test5
    Case 13
    Resume Test6
    Case 16
    Resume Exit_1
    Case 19
    Resume Test8
    Case 22
    Resume Test9
    Case 25
    Resume Exit_1
    Case 28
    Resume Test11
    Case 31
    Resume Test12
    Case 34
    Resume Exit_1
    End Select
    Case 13
    'test not ok for embedded array non an array...
    MArrayServer_fnctTestArrayInVariant = OkArray
    Case Else
    MsgBox Err & Space(1) & Error$ & " MArrayServer_fnctTestArrayInVariant, riga = " & Erl
    End Select

    Resume eXit_fUnction

    End Function

    Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured