|
-
Jan 22nd, 2004, 10:57 AM
#1
Thread Starter
New Member
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
-
Jan 22nd, 2004, 11:21 AM
#2
Addicted Member
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:
Dim arrToPass() as string
arrToPass = PassArray(arrToPass)
'
'
'
Function PassArray(ByVal ArrayPass() as string) as string()
Return ArrayPass
End Function
By the way always use the vbcode blocks when writing code in the post. Its much easier to read.
-
Jan 22nd, 2004, 12:24 PM
#3
Thread Starter
New Member
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:
Function test()
Dim TwoDArray(,) As String
TwoDArray = PassArray(TwoDArray)
End Function
Function PassArray(ByRef ArrayInArgList() As String)
PassArray = ArrayInArgList
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
-
Jan 22nd, 2004, 12:56 PM
#4
Addicted Member
Add string()() at then end of the function and the arg.
Last edited by jwmoore2001; Jan 22nd, 2004 at 12:59 PM.
-
Jan 22nd, 2004, 01:31 PM
#5
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|