Author Topic: multiple array question  (Read 2421 times)

0 Members and 1 Guest are viewing this topic.

Frankolinox

  • Guest
multiple array question
« on: March 23, 2013, 07:38:37 AM »
little problem here in one of the nehe example to convert:

"boxcol(0, 0) = 1.0  : boxcol(1, 0) = 0.0  : boxcol(2, 0)  = 0.0 "

Code: [Select]
' how to dimension this array in oxygen?
'
sys a,b
sys boxcol(a,b) ' ??? =>(a,b)=1.0



'----------- problem --------- //

boxcol(0, 0) = 1.0  : boxcol(1, 0) = 0.0  : boxcol(2, 0)  = 0.0

'----------- problem --------- //


' boxcol(2, 4)  = 1.0

any help is welcome.

frank

Charles Pegge

  • Guest
Re: multiple array question
« Reply #1 on: March 23, 2013, 02:03:04 PM »
Yes, Oxygen has very primitive arrays, so you have to do a little extra work. For 2 dimensional arrays you have to multiply up the rows by the number of columns

'4x4
'single boxcol[16]
indexbase 0
...
a=1 : b=2
...
v=boxcol[a*4+b] 'boxcol[a,b] equiv


Charles

Peter

  • Guest
Re: multiple array question
« Reply #2 on: March 24, 2013, 05:44:13 AM »
'Demo Array 2 dimensions
Code: [Select]
indexbase 0
sys Bloc[12]    'array [3,4] =12 elements

sys z, a, b

Bloc[0]  = 10  '[0,0] =10  
Bloc[1]  = 11  '[0,1] =11  
Bloc[2]  = 22  '[0,2] =22  
Bloc[3]  = 33  '[0,3] =33  
Bloc[4]  = 44  '[1,0] =44    
Bloc[5]  = 55  '[1,1] =55  
Bloc[6]  = 66  '[1,2] =66  
Bloc[7]  = 77  '[1,3] =77  
Bloc[8]  = 88  '[2,0] =88    
Bloc[9]  = 99  '[2,1] =99  
Bloc[10] = 92  '[2,2] =92  
Bloc[11] = 94  '[2,3] =94  

a=2 : b=1
z = a*4+b

print Bloc[z] "    hooray!"

Function Array2D(sys *array, a, b, d2) as sys  'd2 = 2st dimension
         Return array[a*d2+b]
End Function

print Array2D(&Bloc, 1, 3, 4)

Frankolinox

  • Guest
Re: multiple array question
« Reply #3 on: March 26, 2013, 01:35:52 AM »
thank you charles and peter for your example :-) I will try to convert now another openGL example.

multiple arrays do you are planing for some of next oxygen update, charles ;) ?

freebasic example:
Code: [Select]
'' examples/manual/array/redim2d.bas
''
'' NOTICE: This file is part of the FreeBASIC Compiler package and can't
''         be included in other distributions without authorization.
''
'' See Also: http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgRedim
'' --------

'' Define a variable-length array
Dim array() As Integer

'' ReDim array to have 3*4 elements
ReDim array(1 To 3, 1 To 4)

Dim As Integer n = 1, i, j

Print "3 * 4:"
'Print
For i = LBound(array, 1) To UBound(array, 1)
For j = LBound(array, 2) To UBound(array, 2)
    array(i, j) = n
    Print Using "##  "; array(i, j);
    n += 1
Next
Print
Next
Print "go"


'' ReDim Preserve array to have 4*4 elements, preserving the contents
'' (only the first upper bound should be changed)
ReDim Preserve array(1 To 4, 1 To 4) As Integer

Print "4 * 4:"
Print
For i = LBound(array, 1) To UBound(array, 1)
For j = LBound(array, 2) To UBound(array, 2)
    Print Using "##  "; array(i, j);
Next
Print
Next
Print "go"


'' ReDim Preserve array to have 2*4 elements, preserving but trancating the contents
'' (only the first upper bound should be changed)
ReDim Preserve array(1 To 2, 1 To 4) As Integer

Print "2 * 4:"

For i = LBound(array, 1) To UBound(array, 1)
For j = LBound(array, 2) To UBound(array, 2)
    Print Using "##  "; array(i, j);
Next
Print
Next
Print "end"


best regards, frank
« Last Edit: March 26, 2013, 06:33:58 AM by Frankolinox »

Aurel

  • Guest
Re: multiple array question
« Reply #4 on: March 26, 2013, 08:09:27 AM »
Yes ,sometimes is good to have multidimensional arrays ,
I don't have problems with that stuff because i use separate arrays.
Infact in one program i have 32 separate big string arrays which work fine in oxygen.