PDA

View Full Version : DIM a(0 to 10) as single ???



Oscar Ugolini
11-10-2012, 19:46
hi all,
i would know if there is or there wil be in the future a possibility to define an array dimension like this:

Dim a(0 to 10) as single
or
Dim a(0 to varconst) as single

it could be interesting for anyone when "porting" code from C to thinBasic, without change the array, using also element a(0)... in some complicated algorithms i find some difficulties and spend more time to re-adapt all...
thanks
bye, Oscar

Petr Schreiber
11-10-2012, 20:19
Hi Oscar,

I think it is feature worth considering. I would like to ask you to make a feature suggestion in Support section, if possible:
http://www.thinbasic.com/community/projectpost.php?do=addissue&projectid=1&issuetypeid=feature

In the meantime... it is possible to use this workaround functions:


Dim a(11) As Single

arr(a, 0, 128) ' -- Equivalent of a(0) = 128
arr(a, 1, 256) ' -- Equivalent of a(1) = 256
arr(a, 2, 512) ' -- Equivalent of a(2) = 512

MsgBox 0, arr(a, 0) ' -- Equivalent of msgbox 0, a(0)
MsgBox 0, arr(a, 1) ' -- Equivalent of msgbox 0, a(1)
MsgBox 0, arr(a, 2) ' -- Equivalent of msgbox 0, a(2)

Function arr(ByRef myArray() As Single, i As Long, Optional elementValue As Single) As Single

If Function_CParams = 2 Then
' -- Just 2 parameters mean GET operation
Return myArray(i+1)
Else
' -- Default 3 parameters mean SET operation
myArray(i+1) = elementValue
End If

End Function



Petr

Oscar Ugolini
11-10-2012, 20:26
i have considered the option to make an "array function" like your code... thanks for your reply
i'll turn this request to support :)
bye, Oscar