| Posted: 10:34pm 22 Feb 2021 |
Copy link to clipboard |
 Print this post |
|
Here is a little test program that shows the problem.
You can re-dimension an array easily by using ERASE and then DIM again. However, if you pass in an array to a subroutine and try to re-dimension the passed-in array inside the subroutine, things go bad.
Peter, any comments? Thanks! -Bill
' Test for redimensioning an array that is passed ' into a subroutine, as opposed to in the main program. ' It appears that something goes wrong if you try to ' redimension a passed-in array inside the subroutine. ' William M Leue 2/22/2021
option default integer option base 1
' start with a dummy size dim array(2, 2, 2) print "dimension 1: " + str$(bound(array(), 1)) print "dimension 2: " + str$(bound(array(), 2)) print "dimension 3: " + str$(bound(array(), 3))
' Here we redimension the array in the main program. ' This works fine. erase array dim array(10, 10, 10)
print "After redimensioning in main program" print "dimension 1: " + str$(bound(array(), 1)) print "dimension 2: " + str$(bound(array(), 2)) print "dimension 3: " + str$(bound(array(), 3))
' Pass the array into the subroutine 'ReAllocate' ReAllocate array() end
' Here is the subroutine. sub ReAllocate array()
' Verifying the dimensions of the passed-in array print "Looking at array inside the sub ReAllocate" print "dimension 1: " + str$(bound(array(), 1)) print "dimension 2: " + str$(bound(array(), 2)) print "dimension 3: " + str$(bound(array(), 3))
' Here is where things go wrong! ' The erase works but redimensioning produces the ' error: "Error in Line 43: array(5, 5, 5) already declared." erase array dim array(5, 5, 5) '<=== This fails
print "Looking at array inside the sub ReAllocate after redimensioning" print "dimension 1: " + str$(bound(array(), 1)) print "dimension 2: " + str$(bound(array(), 2)) print "dimension 3: " + str$(bound(array(), 3))
end sub
|