I know there have been discussions of this in the past concerning redimensioning arrays in procedures to which they were passed. I know I always came down on the side of it not being a good idea; however, I know some members regularly do it, and supposedly the compiler keeps track of the current dimensions of the array as it is passed about. Deciding to 'live dangerously' and give it a try I immediately ran into problems. However, I see that what I was doing was passing an undimensioned array to a function which, as part of its processing, would determine the proper limits of the array, and dimension it to those limits there before returning execution to the calling function. The calling function (where the array was initially declared but not dimensioned) would then have a properly sized array able to be passed to other procedures for additional processing. Well, that isn't working. On reflection, I'm wondering if the proper technique is to dimension the array initially to some size - perhaps any size, or one large enough to handle any possible value the particular context is capable of giving it, then pass it to the function where it would be resized to the correct dimensions. I havn't tried that yet, but I'm seeing it as the only alternative because passing the uninitialized array isn't working.
Here is a small test program (Console Compiler) that shows the issue with some simple data. As posted it will run but crash as program closing. However, the program is aware of the dimensioning of the array in the procedure and returns a correct UBound back in Main. Note that if you uncomment the commented out line it won't compile as the compiler will balk at the 'undimensioned array' - even though it reports a correct UBound.
Any thoughts on this issue?
Here is a small test program (Console Compiler) that shows the issue with some simple data. As posted it will run but crash as program closing. However, the program is aware of the dimensioning of the array in the procedure and returns a correct UBound back in Main. Note that if you uncomment the commented out line it won't compile as the compiler will balk at the 'undimensioned array' - even though it reports a correct UBound.
Any thoughts on this issue?
Code:
#Compile Exe #Dim All Type SomeThingOrOther First As Long Second As Long AnArray(8) As Byte End Type Function blnSomeProc(Byref SomeType() As SomeThingOrOther) As Long Register i As Long Register j As Long Redim SomeType(2) As SomeThingOrOther For i=0 To 2 SomeType(i).First=i : SomeType(i).Second=i For j=65 To 73 SomeType(i).AnArray(j)=(i*8)+j Next j Next i Function=1 End Function Function PBMain() As Long Local typ() As SomeThingOrOther If blnSomeProc(typ()) Then Print "blnSomeProc() Succeeded! Print "UBound(typ,1) = " UBound(typ,1) 'Print "typ(1).First = " typ(1).First End If WaitKey$ PBMain=0 End Function
Comment