## Position item in an array larger than 3D

General FreeBASIC programming questions.
lrcvs
Posts: 576
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

@ fxm:

Because there is this difference between FreeBASIC and the mathematical formula of 1 element?
fxm
Posts: 9802
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

### Re: Position item in an array larger than 3D

lrcvs wrote:@ fxm:

Because there is this difference between FreeBASIC and the mathematical formula of 1 element?

It is just a problem of notation:
We can consider that:
offset = position - 1
or
position = offset + 1

Offset represents the address difference between the address of an element and the address (beginning) of the allocated memory block:
- the first element (position 1) is put in memory at the offset = 0 (top of memory block)
- the second element (position 2) is put in memory at the offset = 1 (top of memory block + 1)
- the third element (position 3) is put in memory at the offset = 2 (top of memory block + 2)
- and so on...

Code: Select all

`             -----------------------Address X   : element in position 1 : Offset 0            :-----------------------:Address X+1 : element in position 2 : Offset 1            :-----------------------:Address X+2 : element in position 3 : Offset 2            :-----------------------:............................................................................................`
Last edited by fxm on May 23, 2015 6:25, edited 1 time in total.
lrcvs
Posts: 576
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

Ok., thanks!
lrcvs
Posts: 576
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

Hi:

After three years ...

To use it?

What use is?

Has anyone tried to use this in reverse?

For example:
There are 3 sets of 27 elements each (3 * 3 * 3).
Total of 81 elements. (27 * 3 = 81)

question:
The element 68, where it is?

Row = 2
Col = 2
Level = 2
Dimension = 3

As you have done?

regards
fxm
Posts: 9802
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

### Re: Position item in an array larger than 3D

Yes:

Code: Select all

`Dim As Byte array(1 To 27, 1 To 3, 1 To 3, 1 To 3)Print @array(3, 2, 2, 2) - @array(1, 1, 1, 1) + 1Sleep`

Code: Select all

` 68`

Code: Select all

`Dim As Byte array(1 To 27, 1 To 3, 1 To 3, 1 To 3)Dim As Integer I, J, K, LFor I = Lbound(array, 1) To Ubound(array, 1)  For J = Lbound(array, 2) To Ubound(array, 2)    For K = Lbound(array, 3) To Ubound(array, 3)      For L = Lbound(array, 4) To Ubound(array, 4)        If @array(I, J, K, L) - @array(Lbound(array, 1), Lbound(array, 2), Lbound(array, 3), Lbound(array, 4)) + 1 = 68 Then          Exit For, For, For, For        End If      Next L    Next K  Next JNext IPrint I; J; K; LSleep`

Code: Select all

` 3 2 2 2`
lrcvs
Posts: 576
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

Hi, fmx:

It's very good!

Post error, deleted!!
The notified: 25.05.15
By: lrcvs
Last edited by lrcvs on May 24, 2015 23:40, edited 3 times in total.
stylin
Posts: 1253
Joined: Nov 06, 2005 5:19

### Re: Position item in an array larger than 3D

[code=vbnet file=Untitled.bas]scope
const XSIZE = 3
const YSIZE = 2, YPITCH = XSIZE

dim array(YSIZE-1, XSIZE-1) as integer => {{0,1,2},{3,4,5}}

print "2 dimensions:"
for i as integer = 0 to YSIZE*XSIZE - 1
var y = (i ) \ YPITCH
var x = (i - y*YPITCH)
print using "i:# y:# x:# array(y,x):#"; i; y; x; array(y, x)
next i
print
end scope

scope
const XSIZE = 4
const YSIZE = 3, YPITCH = XSIZE
const ZSIZE = 2, ZPITCH = XSIZE*YSIZE

dim array(ZSIZE-1, YSIZE-1, XSIZE-1) as integer => _
{{{ 0, 1, 2, 3},{ 4, 5, 6, 7},{ 8, 9,10,11}}, _
{{12,13,14,15},{16,17,18,19},{20,21,22,23}}}

print "3 dimensions:"
for i as integer = 0 to ZSIZE*YSIZE*XSIZE - 1
var z = (i ) \ ZPITCH
var y = (i - z*ZPITCH ) \ YPITCH
var x = (i - z*ZPITCH - y*YPITCH)
print using "i:## z:# y:# x:# array(z,y,x):##"; i; z; y; x; array(z, y, x)
next i
print
end scope

scope
const XSIZE = 5
const YSIZE = 4, YPITCH = XSIZE
const ZSIZE = 3, ZPITCH = XSIZE*YSIZE
const WSIZE = 2, WPITCH = XSIZE*YSIZE*ZSIZE

dim array(WSIZE-1, ZSIZE-1, YSIZE-1, XSIZE-1) as integer => _
{{{{ 0, 1, 2, 3, 4},{ 5, 6, 7, 8, 9},{ 10, 11, 12, 13, 14},{ 15, 16, 17, 18, 19}}, _
{{ 20, 21, 22, 23, 24},{ 25, 26, 27, 28, 29},{ 30, 31, 32, 33, 34},{ 35, 36, 37, 38, 39}}, _
{{ 40, 41, 42, 43, 44},{ 45, 46, 47, 48, 49},{ 50, 51, 52, 53, 54},{ 55, 56, 57, 58, 59}}}, _
{{{ 60, 61, 62, 63, 64},{ 65, 66, 67, 68, 69},{ 70, 71, 72, 73, 74},{ 75, 76, 77, 78, 79}}, _
{{ 80, 81, 82, 83, 84},{ 85, 86, 87, 88, 89},{ 90, 91, 92, 93, 94},{ 95, 96, 97, 98, 99}}, _
{{100,101,102,103,104},{105,106,107,108,109},{110,111,112,113,114},{115,116,117,118,119}}}}

print "4 dimensions:"
for i as integer = 0 to WSIZE*ZSIZE*YSIZE*XSIZE - 1
var w = (i ) \ WPITCH
var z = (i - w*WPITCH ) \ ZPITCH
var y = (i - w*WPITCH - z*ZPITCH ) \ YPITCH
var x = (i - w*WPITCH - z*ZPITCH - y*YPITCH)
print using "i:### w:# z:# y:# x:# array(w,z,y,x):###"; i; w; z; y; x; array(w, z, y, x)
next i
end scope
[/code]

[code=text file=Untitled.bas]2 dimensions:
i:0 y:0 x:0 array(y,x):0
i:1 y:0 x:1 array(y,x):1
i:2 y:0 x:2 array(y,x):2
i:3 y:1 x:0 array(y,x):3
i:4 y:1 x:1 array(y,x):4
i:5 y:1 x:2 array(y,x):5

3 dimensions:
i: 0 z:0 y:0 x:0 array(z,y,x): 0
i: 1 z:0 y:0 x:1 array(z,y,x): 1
i: 2 z:0 y:0 x:2 array(z,y,x): 2
i: 3 z:0 y:0 x:3 array(z,y,x): 3
i: 4 z:0 y:1 x:0 array(z,y,x): 4
i: 5 z:0 y:1 x:1 array(z,y,x): 5
i: 6 z:0 y:1 x:2 array(z,y,x): 6
i: 7 z:0 y:1 x:3 array(z,y,x): 7
i: 8 z:0 y:2 x:0 array(z,y,x): 8
i: 9 z:0 y:2 x:1 array(z,y,x): 9
i:10 z:0 y:2 x:2 array(z,y,x):10
i:11 z:0 y:2 x:3 array(z,y,x):11
i:12 z:1 y:0 x:0 array(z,y,x):12
i:13 z:1 y:0 x:1 array(z,y,x):13
i:14 z:1 y:0 x:2 array(z,y,x):14
i:15 z:1 y:0 x:3 array(z,y,x):15
i:16 z:1 y:1 x:0 array(z,y,x):16
i:17 z:1 y:1 x:1 array(z,y,x):17
i:18 z:1 y:1 x:2 array(z,y,x):18
i:19 z:1 y:1 x:3 array(z,y,x):19
i:20 z:1 y:2 x:0 array(z,y,x):20
i:21 z:1 y:2 x:1 array(z,y,x):21
i:22 z:1 y:2 x:2 array(z,y,x):22
i:23 z:1 y:2 x:3 array(z,y,x):23

4 dimensions:
i: 0 w:0 z:0 y:0 x:0 array(w,z,y,x): 0
i: 1 w:0 z:0 y:0 x:1 array(w,z,y,x): 1
i: 2 w:0 z:0 y:0 x:2 array(w,z,y,x): 2
i: 3 w:0 z:0 y:0 x:3 array(w,z,y,x): 3
i: 4 w:0 z:0 y:0 x:4 array(w,z,y,x): 4
i: 5 w:0 z:0 y:1 x:0 array(w,z,y,x): 5
i: 6 w:0 z:0 y:1 x:1 array(w,z,y,x): 6
i: 7 w:0 z:0 y:1 x:2 array(w,z,y,x): 7
i: 8 w:0 z:0 y:1 x:3 array(w,z,y,x): 8
i: 9 w:0 z:0 y:1 x:4 array(w,z,y,x): 9
i: 10 w:0 z:0 y:2 x:0 array(w,z,y,x): 10
i: 11 w:0 z:0 y:2 x:1 array(w,z,y,x): 11
i: 12 w:0 z:0 y:2 x:2 array(w,z,y,x): 12
i: 13 w:0 z:0 y:2 x:3 array(w,z,y,x): 13
i: 14 w:0 z:0 y:2 x:4 array(w,z,y,x): 14
i: 15 w:0 z:0 y:3 x:0 array(w,z,y,x): 15
i: 16 w:0 z:0 y:3 x:1 array(w,z,y,x): 16
i: 17 w:0 z:0 y:3 x:2 array(w,z,y,x): 17
i: 18 w:0 z:0 y:3 x:3 array(w,z,y,x): 18
i: 19 w:0 z:0 y:3 x:4 array(w,z,y,x): 19
i: 20 w:0 z:1 y:0 x:0 array(w,z,y,x): 20
i: 21 w:0 z:1 y:0 x:1 array(w,z,y,x): 21
i: 22 w:0 z:1 y:0 x:2 array(w,z,y,x): 22
i: 23 w:0 z:1 y:0 x:3 array(w,z,y,x): 23
i: 24 w:0 z:1 y:0 x:4 array(w,z,y,x): 24
i: 25 w:0 z:1 y:1 x:0 array(w,z,y,x): 25
i: 26 w:0 z:1 y:1 x:1 array(w,z,y,x): 26
i: 27 w:0 z:1 y:1 x:2 array(w,z,y,x): 27
i: 28 w:0 z:1 y:1 x:3 array(w,z,y,x): 28
i: 29 w:0 z:1 y:1 x:4 array(w,z,y,x): 29
i: 30 w:0 z:1 y:2 x:0 array(w,z,y,x): 30
i: 31 w:0 z:1 y:2 x:1 array(w,z,y,x): 31
i: 32 w:0 z:1 y:2 x:2 array(w,z,y,x): 32
i: 33 w:0 z:1 y:2 x:3 array(w,z,y,x): 33
i: 34 w:0 z:1 y:2 x:4 array(w,z,y,x): 34
i: 35 w:0 z:1 y:3 x:0 array(w,z,y,x): 35
i: 36 w:0 z:1 y:3 x:1 array(w,z,y,x): 36
i: 37 w:0 z:1 y:3 x:2 array(w,z,y,x): 37
i: 38 w:0 z:1 y:3 x:3 array(w,z,y,x): 38
i: 39 w:0 z:1 y:3 x:4 array(w,z,y,x): 39
i: 40 w:0 z:2 y:0 x:0 array(w,z,y,x): 40
i: 41 w:0 z:2 y:0 x:1 array(w,z,y,x): 41
i: 42 w:0 z:2 y:0 x:2 array(w,z,y,x): 42
i: 43 w:0 z:2 y:0 x:3 array(w,z,y,x): 43
i: 44 w:0 z:2 y:0 x:4 array(w,z,y,x): 44
i: 45 w:0 z:2 y:1 x:0 array(w,z,y,x): 45
i: 46 w:0 z:2 y:1 x:1 array(w,z,y,x): 46
i: 47 w:0 z:2 y:1 x:2 array(w,z,y,x): 47
i: 48 w:0 z:2 y:1 x:3 array(w,z,y,x): 48
i: 49 w:0 z:2 y:1 x:4 array(w,z,y,x): 49
i: 50 w:0 z:2 y:2 x:0 array(w,z,y,x): 50
i: 51 w:0 z:2 y:2 x:1 array(w,z,y,x): 51
i: 52 w:0 z:2 y:2 x:2 array(w,z,y,x): 52
i: 53 w:0 z:2 y:2 x:3 array(w,z,y,x): 53
i: 54 w:0 z:2 y:2 x:4 array(w,z,y,x): 54
i: 55 w:0 z:2 y:3 x:0 array(w,z,y,x): 55
i: 56 w:0 z:2 y:3 x:1 array(w,z,y,x): 56
i: 57 w:0 z:2 y:3 x:2 array(w,z,y,x): 57
i: 58 w:0 z:2 y:3 x:3 array(w,z,y,x): 58
i: 59 w:0 z:2 y:3 x:4 array(w,z,y,x): 59
i: 60 w:1 z:0 y:0 x:0 array(w,z,y,x): 60
i: 61 w:1 z:0 y:0 x:1 array(w,z,y,x): 61
i: 62 w:1 z:0 y:0 x:2 array(w,z,y,x): 62
i: 63 w:1 z:0 y:0 x:3 array(w,z,y,x): 63
i: 64 w:1 z:0 y:0 x:4 array(w,z,y,x): 64
i: 65 w:1 z:0 y:1 x:0 array(w,z,y,x): 65
i: 66 w:1 z:0 y:1 x:1 array(w,z,y,x): 66
i: 67 w:1 z:0 y:1 x:2 array(w,z,y,x): 67
i: 68 w:1 z:0 y:1 x:3 array(w,z,y,x): 68
i: 69 w:1 z:0 y:1 x:4 array(w,z,y,x): 69
i: 70 w:1 z:0 y:2 x:0 array(w,z,y,x): 70
i: 71 w:1 z:0 y:2 x:1 array(w,z,y,x): 71
i: 72 w:1 z:0 y:2 x:2 array(w,z,y,x): 72
i: 73 w:1 z:0 y:2 x:3 array(w,z,y,x): 73
i: 74 w:1 z:0 y:2 x:4 array(w,z,y,x): 74
i: 75 w:1 z:0 y:3 x:0 array(w,z,y,x): 75
i: 76 w:1 z:0 y:3 x:1 array(w,z,y,x): 76
i: 77 w:1 z:0 y:3 x:2 array(w,z,y,x): 77
i: 78 w:1 z:0 y:3 x:3 array(w,z,y,x): 78
i: 79 w:1 z:0 y:3 x:4 array(w,z,y,x): 79
i: 80 w:1 z:1 y:0 x:0 array(w,z,y,x): 80
i: 81 w:1 z:1 y:0 x:1 array(w,z,y,x): 81
i: 82 w:1 z:1 y:0 x:2 array(w,z,y,x): 82
i: 83 w:1 z:1 y:0 x:3 array(w,z,y,x): 83
i: 84 w:1 z:1 y:0 x:4 array(w,z,y,x): 84
i: 85 w:1 z:1 y:1 x:0 array(w,z,y,x): 85
i: 86 w:1 z:1 y:1 x:1 array(w,z,y,x): 86
i: 87 w:1 z:1 y:1 x:2 array(w,z,y,x): 87
i: 88 w:1 z:1 y:1 x:3 array(w,z,y,x): 88
i: 89 w:1 z:1 y:1 x:4 array(w,z,y,x): 89
i: 90 w:1 z:1 y:2 x:0 array(w,z,y,x): 90
i: 91 w:1 z:1 y:2 x:1 array(w,z,y,x): 91
i: 92 w:1 z:1 y:2 x:2 array(w,z,y,x): 92
i: 93 w:1 z:1 y:2 x:3 array(w,z,y,x): 93
i: 94 w:1 z:1 y:2 x:4 array(w,z,y,x): 94
i: 95 w:1 z:1 y:3 x:0 array(w,z,y,x): 95
i: 96 w:1 z:1 y:3 x:1 array(w,z,y,x): 96
i: 97 w:1 z:1 y:3 x:2 array(w,z,y,x): 97
i: 98 w:1 z:1 y:3 x:3 array(w,z,y,x): 98
i: 99 w:1 z:1 y:3 x:4 array(w,z,y,x): 99
i:100 w:1 z:2 y:0 x:0 array(w,z,y,x):100
i:101 w:1 z:2 y:0 x:1 array(w,z,y,x):101
i:102 w:1 z:2 y:0 x:2 array(w,z,y,x):102
i:103 w:1 z:2 y:0 x:3 array(w,z,y,x):103
i:104 w:1 z:2 y:0 x:4 array(w,z,y,x):104
i:105 w:1 z:2 y:1 x:0 array(w,z,y,x):105
i:106 w:1 z:2 y:1 x:1 array(w,z,y,x):106
i:107 w:1 z:2 y:1 x:2 array(w,z,y,x):107
i:108 w:1 z:2 y:1 x:3 array(w,z,y,x):108
i:109 w:1 z:2 y:1 x:4 array(w,z,y,x):109
i:110 w:1 z:2 y:2 x:0 array(w,z,y,x):110
i:111 w:1 z:2 y:2 x:1 array(w,z,y,x):111
i:112 w:1 z:2 y:2 x:2 array(w,z,y,x):112
i:113 w:1 z:2 y:2 x:3 array(w,z,y,x):113
i:114 w:1 z:2 y:2 x:4 array(w,z,y,x):114
i:115 w:1 z:2 y:3 x:0 array(w,z,y,x):115
i:116 w:1 z:2 y:3 x:1 array(w,z,y,x):116
i:117 w:1 z:2 y:3 x:2 array(w,z,y,x):117
i:118 w:1 z:2 y:3 x:3 array(w,z,y,x):118
i:119 w:1 z:2 y:3 x:4 array(w,z,y,x):119
[/code]
lrcvs
Posts: 576
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

Hi, fxm, styling and all.

Well, I think that I have solved the problem with math.

The program does the following:
Knowing a position, we calculate the row, column, the level and dimension / block.

The data required are:
Know what position we want to search, and the number of rows, number of columns and the number of levels in a single dimension / block.

This program does the calculation for any dimension <= 4D.

Dimension> = 4D, indicates to block or dimension, the position belongs to look, then just make a couple of operations and obtain the correct position.

Code: Select all

`DIM AS INTEGER C,CO,D,F,H,L,P,RCLSINPUT "QTY ROWS (Rows  <=  Cols)  = ";  RINPUT "QTY COLS (Cols >=Rows)  = ";CINPUT "QTY LEV   =  ";LINPUT "FIND  POSITION  = ";PH = L'CALCULATE DIMENSION/BLOCKIF  P MOD  (R*C*L)  <> 0 THEND =  INT(P/(R*C*L))+1ELSED = INT(P/(R*C*L))END IF'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'CALCULATE  LEVELL =  INT(P/(R*C))+1IF P  MOD (R*C)  =  0  THEN L  =  L-1':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'CALCULATE COLIF P  <  C THEN CO = PIF P  >= C  THEN  CO =  P MOD  CIF  P MOD C = 0 THEN  CO = C  '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'CALCULATE ROWF =  ((P-CO-((R*C)*(L-1)))/C)+1'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::PRINTCOLOR  12PRINT  "BLO = ";D;" ROW = ";F; " COL = ";CO; " LEV = ";L-((D-1)*H)SLEEPEND`

Simple example:
Calculate the row, column, and level of the position 26, in a 3D block 3 rows, 3 columns, 3 levels.
The solution is: row 3, column 2, Level 3

To calculate blocks / dimensions 4D, we simply indicate the size of a block and the position we want to search.

Simple example:
Calculate the row, column, and level of position 53, in a 3D block 3 rows, 3 columns, 3 levels.
The solution is: Dim / Blo 2 Row 3, column 2, Level 3.

To calculate blocks / size> = 4D, we simply indicate the size of a block and the position we want to search. The program will indicate that the block number is, the row, column and level.

I think some mathematical formulas, are faster and simple loops "For / Next".

I wish you like this program.!
lrcvs
Posts: 576
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

To fxm:

Hi, fxm:

Your variables (I, J, K, L) are?

I = Row ? Col ?, Level? , Dim?
J = Row ? Col ?, Level? , Dim?
K = Row ?, Col ? , Level? , Dim?
L = Row ?, Col ?, Level? , Dim?

Regards
fxm
Posts: 9802
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

### Re: Position item in an array larger than 3D

Multidimensional arrays are stored in this definite order:
- values differing only in the last index are contiguous (row-major order).

So, referring to the notation:
array(I, J, K, L)
L is the row index
K is the column index
.....
.....

Example for a three-dimensional array:

Code: Select all

`Dim As Integer array(1 To 3, 1 To 5, 1 To 4)For J As Integer = Lbound(array, 1) To Ubound(array, 1)  For K As Integer = Lbound(array, 2) To Ubound(array, 2)    For L As Integer = Lbound(array, 3) To Ubound(array, 3)      Print @array(J, K, L) - @array(Lbound(array, 1), Lbound(array, 2), Lbound(array, 3)),    Next L    Print  Next K  PrintNext JSleep`

Code: Select all

` 0             1             2             3 4             5             6             7 8             9             10            11 12            13            14            15 16            17            18            19 20            21            22            23 24            25            26            27 28            29            30            31 32            33            34            35 36            37            38            39 40            41            42            43 44            45            46            47 48            49            50            51 52            53            54            55 56            57            58            59`
lrcvs
Posts: 576
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

Hi, fxm

OK, is coincidence YOUR POST OF DATE 23.05.15
Block 3
Row 2
Col 2
Level 2

Thanks, regards!
lrcvs
Posts: 576
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

Hi, fxm:

Your program is good, but the 1,1,1 position, can not be "0" has to be "1" and the last position is not 50, it must be = "60" = 4 * 5 * 3

Code: Select all

`0 R =  1 C =  1 L =  11 R =  2 C =  1 L =  12 R =  3 C =  1 L =  13 R =  4 C =  1 L =  14 R =  1 C =  2 L =  15 R =  2 C =  2 L =  16 R =  3 C =  2 L =  17 R =  4 C =  2 L =  18 R =  1 C =  3 L =  19 R =  2 C =  3 L =  110 R =  3 C =  3 L =  111 R =  4 C =  3 L =  112 R =  1 C =  4 L =  113 R =  2 C =  4 L =  114 R =  3 C =  4 L =  115 R =  4 C =  4 L =  116 R =  1 C =  5 L =  117 R =  2 C =  5 L =  118 R =  3 C =  5 L =  119 R =  4 C =  5 L =  120 R =  1 C =  1 L =  221 R =  2 C =  1 L =  222 R =  3 C =  1 L =  223 R =  4 C =  1 L =  224 R =  1 C =  2 L =  225 R =  2 C =  2 L =  226 R =  3 C =  2 L =  227 R =  4 C =  2 L =  228 R =  1 C =  3 L =  229 R =  2 C =  3 L =  230 R =  3 C =  3 L =  231 R =  4 C =  3 L =  232 R =  1 C =  4 L =  233 R =  2 C =  4 L =  234 R =  3 C =  4 L =  235 R =  4 C =  4 L =  236 R =  1 C =  5 L =  237 R =  2 C =  5 L =  238 R =  3 C =  5 L =  239 R =  4 C =  5 L =  240 R =  1 C =  1 L =  341 R =  2 C =  1 L =  342 R =  3 C =  1 L =  343 R =  4 C =  1 L =  344 R =  1 C =  2 L =  345 R =  2 C =  2 L =  346 R =  3 C =  2 L =  347 R =  4 C =  2 L =  348 R =  1 C =  3 L =  349 R =  2 C =  3 L =  350 R =  3 C =  3 L =  351 R =  4 C =  3 L =  352 R =  1 C =  4 L =  353 R =  2 C =  4 L =  354 R =  3 C =  4 L =  355 R =  4 C =  4 L =  356 R =  1 C =  5 L =  357 R =  2 C =  5 L =  358 R =  3 C =  5 L =  359 R =  4 C =  5 L =  3`

regards
lrcvs
Posts: 576
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

HI, fxm:

My program:

Code: Select all

`POS =  1 BLO =  1 ROW =  1 COL =  1 LEV =  1POS =  2 BLO =  1 ROW =  1 COL =  2 LEV =  1POS =  3 BLO =  1 ROW =  1 COL =  3 LEV =  1POS =  4 BLO =  1 ROW =  1 COL =  4 LEV =  1POS =  5 BLO =  1 ROW =  1 COL =  5 LEV =  1POS =  6 BLO =  1 ROW =  2 COL =  1 LEV =  1POS =  7 BLO =  1 ROW =  2 COL =  2 LEV =  1POS =  8 BLO =  1 ROW =  2 COL =  3 LEV =  1POS =  9 BLO =  1 ROW =  2 COL =  4 LEV =  1POS =  10 BLO =  1 ROW =  2 COL =  5 LEV =  1POS =  11 BLO =  1 ROW =  3 COL =  1 LEV =  1POS =  12 BLO =  1 ROW =  3 COL =  2 LEV =  1POS =  13 BLO =  1 ROW =  3 COL =  3 LEV =  1POS =  14 BLO =  1 ROW =  3 COL =  4 LEV =  1POS =  15 BLO =  1 ROW =  3 COL =  5 LEV =  1POS =  16 BLO =  1 ROW =  4 COL =  1 LEV =  1POS =  17 BLO =  1 ROW =  4 COL =  2 LEV =  1POS =  18 BLO =  1 ROW =  4 COL =  3 LEV =  1POS =  19 BLO =  1 ROW =  4 COL =  4 LEV =  1POS =  20 BLO =  1 ROW =  4 COL =  5 LEV =  1POS =  21 BLO =  2 ROW =  1 COL =  1 LEV =  1POS =  22 BLO =  1 ROW =  1 COL =  2 LEV =  2POS =  23 BLO =  1 ROW =  1 COL =  3 LEV =  2POS =  24 BLO =  1 ROW =  1 COL =  4 LEV =  2POS =  25 BLO =  1 ROW =  1 COL =  5 LEV =  2POS =  26 BLO =  1 ROW =  2 COL =  1 LEV =  2POS =  27 BLO =  1 ROW =  2 COL =  2 LEV =  2POS =  28 BLO =  1 ROW =  2 COL =  3 LEV =  2POS =  29 BLO =  1 ROW =  2 COL =  4 LEV =  2POS =  30 BLO =  1 ROW =  2 COL =  5 LEV =  2POS =  31 BLO =  1 ROW =  3 COL =  1 LEV =  2POS =  32 BLO =  1 ROW =  3 COL =  2 LEV =  2POS =  33 BLO =  1 ROW =  3 COL =  3 LEV =  2POS =  34 BLO =  1 ROW =  3 COL =  4 LEV =  2POS =  35 BLO =  1 ROW =  3 COL =  5 LEV =  2POS =  36 BLO =  1 ROW =  4 COL =  1 LEV =  2POS =  37 BLO =  1 ROW =  4 COL =  2 LEV =  2POS =  38 BLO =  1 ROW =  4 COL =  3 LEV =  2POS =  39 BLO =  1 ROW =  4 COL =  4 LEV =  2POS =  40 BLO =  1 ROW =  4 COL =  5 LEV =  2POS =  41 BLO =  2 ROW =  1 COL =  1 LEV =  1POS =  42 BLO =  1 ROW =  1 COL =  2 LEV =  3POS =  43 BLO =  1 ROW =  1 COL =  3 LEV =  3POS =  44 BLO =  1 ROW =  1 COL =  4 LEV =  3POS =  45 BLO =  1 ROW =  1 COL =  5 LEV =  3POS =  46 BLO =  1 ROW =  2 COL =  1 LEV =  3POS =  47 BLO =  1 ROW =  2 COL =  2 LEV =  3POS =  48 BLO =  1 ROW =  2 COL =  3 LEV =  3POS =  49 BLO =  1 ROW =  2 COL =  4 LEV =  3POS =  50 BLO =  1 ROW =  2 COL =  5 LEV =  3POS =  51 BLO =  1 ROW =  3 COL =  1 LEV =  3POS =  52 BLO =  1 ROW =  3 COL =  2 LEV =  3POS =  53 BLO =  1 ROW =  3 COL =  3 LEV =  3POS =  54 BLO =  1 ROW =  3 COL =  4 LEV =  3POS =  55 BLO =  1 ROW =  3 COL =  5 LEV =  3POS =  56 BLO =  1 ROW =  4 COL =  1 LEV =  3POS =  57 BLO =  1 ROW =  4 COL =  2 LEV =  3POS =  58 BLO =  1 ROW =  4 COL =  3 LEV =  3POS =  59 BLO =  1 ROW =  4 COL =  4 LEV =  3POS =  60 BLO =  1 ROW =  4 COL =  5 LEV =  3`

regards
fxm
Posts: 9802
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

### Re: Position item in an array larger than 3D

My program displays the offset of each element with regard to the first element (not the position):
Print @array(J, K, L) - @array(Lbound(array, 1), Lbound(array, 2), Lbound(array, 3))

So consequently:
- Offset of the 1 st element = 0
- Offset of the 60 th element = 59

(Offset = Position - 1)
lrcvs
Posts: 576
Joined: Mar 06, 2008 19:27
Location: Spain

### Re: Position item in an array larger than 3D

Hi, fxm:

Ok!, Both systems (programs) are correct!

Regards