I can put static variable at the start of procedure like that.
Code: Select all
sub test()
static as long arr()
end sub
Code: Select all
if ubound(arr)=-1 then redim arr(1023)
Code: Select all
static scope
redim arr(1023)
end scope
Code: Select all
sub test()
static as long arr()
end sub
Code: Select all
if ubound(arr)=-1 then redim arr(1023)
Code: Select all
static scope
redim arr(1023)
end scope
Code: Select all
sub test(init as boolean = false)
static as long array()
if init then
redim array(1023)
End If
print ubound (array)
End Sub
test
test(1)
test
Code: Select all
Sub test()
Dim As Integer ub = 1023
Static As Long array(ub) '' pre-sized dynamic array
End Sub
Code: Select all
Sub test()
Static As Long array(Type<Integer>(1023)) '' pre-sized dynamic array
End Sub
I am sorry,what is the difference betweenfxm wrote: ↑Dec 13, 2024 10:02 Another workaround:or more compact:Code: Select all
Sub test() Dim As Integer ub = 1023 Static As Long array(ub) '' pre-sized dynamic array End Sub
Code: Select all
Sub test() Static As Long array(Type<Integer>(1023)) '' pre-sized dynamic array End Sub
Code: Select all
Static As Long array(Type<Integer>(1023))
Code: Select all
Static As Long array(1023)
If the values used with Dim to declare the dimensions of an array are all constants, the array will be created fixed length (of Static size, unless Option Dynamic is specified), while using one or more variables to declare the dimensions of an array makes it variable length, even if Option Static is in effect.
Code: Select all
Function ArraySize() As Long
Return 1023
End Function
Static As Long array(ArraySize())
It can create not only a temporary copy of an user defined type, but also a temporary copy of predefined data-type as a variable-length string or any numeric data-type (all standard data-types excluding fixed-length strings).
Code: Select all
#cmdline "-exx"
type udt
as long a(20)
end type
function isdynamic overload(a() as long) as boolean
on local error goto fin
var k=abs(ubound(a))
redim a(2*k)
return iif(ubound(a)=k,false,true)
fin:
end function
function isdynamic overload(a() as udt) as boolean
on local error goto fin
var k=abs(ubound(a))
redim a(2*k)
return iif(ubound(a)=k,false,true)
fin:
end function
redim as long arr(23)
print isdynamic(arr())
dim as long arr2(23)
print isdynamic(arr2())
static as long arr3(12)
print isdynamic(arr3())
static as long arr4(type<integer>12)
print isdynamic(arr4())
print
static as udt z(rnd*12)
print isdynamic(z())
static as udt z2()
print isdynamic(z2())
redim z2(1 to 5)
print isdynamic(z2())
dim as udt z3(-5 to -1)
print isdynamic(z3())
sleep
Yes, I increased the length of the instance name.deltarho[1859] wrote: ↑Dec 14, 2024 12:48 The 'With' example is not a goof example. Who in their right mind would use it for 'ex'. If 'ex' was a longer name, then the longer it was, the more sense it would be to use 'With'.