Results 1 to 5 of 5

Thread: Passing multi-dimensional arrays to functions

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    6

    Passing multi-dimensional arrays to functions

    Just starting using VB.net

    In VB6 I could..

    Dim Array1(,) as string
    dim blah as string

    stuff happens to array1, and it gets filled with stuff

    array1= passingarray(array1)


    Function passingarray(Array2() as string)

    stuff happens

    passingarray=array2
    end function

    Now it's telling me that I can't convert the two dimensional array array1 into the one dimensional array2. Can't set the array dimensions on the parameter list for array2 either.

    Any suggestions? Course I need to recode this part anyway. Maybe it's a sign

  2. #2
    Addicted Member
    Join Date
    Apr 2002
    Location
    California
    Posts
    160
    Ok what exactly are you asking here? Are you asking how to convert a 2-Dimensional Array into a 1-Dimensional? (Because you can't) or are you saying you are getting that error when trying to set the array?

    VB Code:
    1. Dim arrToPass() as string
    2.  
    3. arrToPass = PassArray(arrToPass)
    4. '
    5. '
    6. '
    7. Function PassArray(ByVal ArrayPass() as string) as string()
    8.  
    9. Return ArrayPass
    10.  
    11. End Function

    By the way always use the vbcode blocks when writing code in the post. Its much easier to read.
    Jason Moore

    Software Engineer, Database Architect, Web Designer

    (C#,VB/NET,ASP/NET,COLDFUSION,JAVASCRIPT,SQL)

    http://www.gatorstudios.com
    [email protected]

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    6
    Basically asking how I pass a 2 dimension+ array to a function - having an array in the argument list appears to default to a 1 dimension array.

    So in my code
    VB Code:
    1. Function test()
    2.         Dim TwoDArray(,) As String
    3.         TwoDArray = PassArray(TwoDArray)
    4.     End Function
    5.     Function PassArray(ByRef ArrayInArgList() As String)
    6.         PassArray = ArrayInArgList
    7.     End Function

    The errors I get are " Value of type '2-dimensional array of String' cannot be converted to '1-dimensional array of String' because the array types have different numbers of dimensions."

    Basically saying that ArrayInArgList is a 1d array, and because of that it can't copy the 2d array TwoDArray to it . But I can't set ArrayInArgList as a 2d array anywhere it seems

  4. #4
    Addicted Member
    Join Date
    Apr 2002
    Location
    California
    Posts
    160
    Add string()() at then end of the function and the arg.
    Last edited by jwmoore2001; Jan 22nd, 2004 at 12:59 PM.
    Jason Moore

    Software Engineer, Database Architect, Web Designer

    (C#,VB/NET,ASP/NET,COLDFUSION,JAVASCRIPT,SQL)

    http://www.gatorstudios.com
    [email protected]

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    6
    I'm curious as to what the string()() means, instead of using string(,) . For what I was trying to solve in my application string(,) worked, but string()() didn't. Kept saying it was 1d still (actually it changed everything to 1d, but said one 1d wasnt derived of string, or something).

    Thanks for the pointer though, got me on the right path

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