Wondering why multiple conditional REDIM()s are treated differently when they are in a different code block than their corresponding DIM()...
I get a compile error when there are multiple REDIM()s in an IF...ELSE block - and those REDIM()s are in the same code block as their DIM().... whether the DIM()/REDIM()s are together in the main block or in a function block.
Code: Select all
''' REDIM() ERROR...
dim x() as UByte
if true then
redim x( 0 to 255) as UByte
else
''' error 36: Wrong number of dimensions, X in 'redim x( 0 to 255, 1 to 7) as UByte'
redim x( 0 to 255, 1 to 7) as UByte
END IF
print
print "ubound( x, 0) = "; ubound( x, 0)
print
Code: Select all
''' REDIM() ERROR...
sub redimtest( )
dim x() as UByte
if true then
redim x( 0 to 255) as UByte
else
''' error 36: Wrong number of dimensions, X in 'redim x( 0 to 255, 1 to 7) as UByte'
redim x( 0 to 255, 1 to 7) as UByte
END IF
print
print "ubound( x, 0) = "; ubound( x, 0)
print
END SUB
redimtest( )
Code: Select all
''' REDIM() ERROR...
dim x() as UByte
SCOPE
if true then
redim x( 0 to 255) as UByte
else
''' error 36: Wrong number of dimensions, X in 'redim x( 0 to 255, 1 to 7) as UByte'
redim x( 0 to 255, 1 to 7) as UByte
END IF
print
print "ubound( x, 0) = "; ubound( x, 0)
print
END SCOPE
Code: Select all
''' REDIM() WORKS...
sub redimx( rx() as ubyte)
if true then
redim rx( 0 to 255) as UByte
else
redim rx( 0 to 255, 1 to 7) as UByte
END IF
END SUB
dim x() as UByte
redimx( x() )
print
print "ubound( x, 0) = "; ubound( x, 0)
print