|
Post by bluatigro on Apr 22, 2018 13:27:11 GMT
see what happens :
dim a( 20 )
a( 0 ) = 1 a( 1 ) = 2
print a( 0 ) , a( 1 ) call swap a( 0 ) , a( 1 ) print a( 0 ) , a( 1 )
print "[ end byref test ]"
end sub swap byref a , byref b h = a a = b b = a end sub
|
|
|
Post by Rod on Apr 22, 2018 14:01:57 GMT
This is not a bug IMHO. Arrays are global by default so it does not make sense to me to be passing them as parameters when calling a SUB.
Over and above that the help file is quite clear in stating that BYREF only acts on string and numeric variables. Arrays, literals and computed values are NOT supported for BYREF.
|
|
|
Post by B+ on Apr 22, 2018 19:15:36 GMT
Shouldn't that last line read b = h ?
|
|
|
Post by carlgundel on Apr 22, 2018 21:25:26 GMT
It's true that support for passing elements of an array or even arrays themselves would be useful, of course. Just BASIC and Liberty BASIC do not support this language feature, but this is not a bug because it is working as designed.
Perhaps in the future this feature or something similar can be added.
|
|
|
Post by B+ on Apr 23, 2018 13:26:33 GMT
Here is a fix for bluatigro's swapping of array elements:
dim a( 20 )
a( 0 ) = 1 a( 1 ) = 2
print a( 0 ) , a( 1 ) call swapArrayElements 0 , 1 print a( 0 ) , a( 1 )
print "[ end of swap test ]"
end sub swapArrayElements ia , ja h = a(ia) a(ia) = a(ja) a(ja) = h end sub
Sure, sure we have to do this for each array we might want to swap elements with different swap subs, oh well...
Edits by Rod tidying thread.
|
|