array ..? what is problem there?
'14:08 26/05/2018
'
class ArrayObjectXY
==================
sys pA
int sc,sx,sy
'
method constructor(int x,y)
sc=sizeof(double) : sx=x : sy=y
pA=getmemory sc*x*y
end method
'
method destructor()
freememory pA
sc=0 : sx=0 : sy=0
end method
'
method dv(int x,y) as double
x-- : y-- 'BASE 0
double da at pA+sc*(x+y*sx)
return da
end method
'
method dv(int x,y,double a)
x-- : y-- 'BASE 0
double da at pA+sc*(x+y*sx)
da=a
end method
'
end class
'TESTS:
new ArrayObjectXY ta(100,200)
ta.dv(10,20)=42
print "ok " ta.dv(10,20)
del ta
includepath "$/inc/"
$filename "Statistics_1.0.dll"
$dll
include "RTL32.inc"
extern export
Function Statistics(byref Resul[] as int, byval Cq as int, byval Ct as int, byval Lt as long)
', byref Tab_Atra() as int )
'sub Statistics( *Resul() as int,
' byval Cq as int,
' byval Ct as int,
' byval Lt as int,
' *Tab_Atra() as int )
indexbase 0
dim Tab_Atra() as int
dim C, L, Atr0() as int
dim n1 , n2 as double
dim int MAIOR_REPT, MAIOR_ATR
cq=cq-1
Ct=Ct-1
Lt=lt-1
Atr0(Ct)
For c = 0 To cq
Atr0((Resul)[L*cq+C]) = 1' Atr0(Resul(1, c)) = 1
Next
If Atr0(c) = 1 Then
Tab_Atra(L*cq+C) = 1
Atr0(c) = 0
Else
Tab_Atra(L*cq+C) = -1
End If
For L = 1 To lt
For c = 0 To cq
Atr0((Resul)[L*cq+C]) = 1
Next
For c = 0 To ct
n1=L*ct+C
n2=(L-1)*ct+C
If Atr0(c) = 1 Then
If Tab_Atra(n2) > 0 Then
Tab_Atra(n1) = Tab_Atra(n2) + 1
If Tab_Atra(n1) > MAIOR_REPT Then MAIOR_REPT = Tab_Atra(n1)
Else
Tab_Atra(n1) = 1
End If
Atr0(c) = 0
Else
If Tab_Atra(n2) > 0 Then
Tab_Atra(n1) = -1
Else
Tab_Atra(n1) = Tab_Atra(n2) - 1
If Tab_Atra(n1) < MAIOR_ATR Then MAIOR_ATR = Tab_Atra(n1)
End If
End If
Next
Next
end Function
Function Statistics( int byref Resul ,
byval Cq as int,
byval Ct as int,
byval Lt as int,
int byref Tab_Atra )
'both one and the other works
Function Statistics(int *Resul, Cq , byval Ct ,Lt ,*Tab_Atra )
includepath "$/inc/"
$filename "Statistics_1.0.dll"
$dll
include "RTL32.inc"
extern export
Function Statistics(int *Resul,int Cq ,int byval Ct ,int Lt ,int *Tab_Atra )
indexbase 0
dim int MAIOR_REPT, MAIOR_ATR
int aa
aa=ct-1
dim int C, L, Atr0(80)
dim n1 , n2 as double
l=0
For c = 0 To cq-1
n1=l+c*lt
Atr0(Resul[n1]-1) = 1
Next
For c = 0 To ct-1
n1=l+c*lt
If Atr0(c) = 1 Then
Tab_Atra[n1] = 1
Atr0(c) = 0
Else
Tab_Atra[n1] = -1
End If
Next
For L = 1 To Lt - 1
For c = 0 To cq - 1
n1=l+c*lt
Atr0(Resul[n1]-1) = 1
Next
For c = 0 To Ct - 1
n1 = L + c * Lt
n2 = L - 1+c*lt
If Atr0(c) = 1 Then
If Tab_Atra(n2) > 0 Then
Tab_Atra(n1) = Tab_Atra(n2) + 1
' If Tab_Atra(n1) > MAIOR_REPT Then MAIOR_REPT = Tab_Atra(n1)
Else
Tab_Atra(n1) = 1
End If
Atr0(c) = 0
Else
If Tab_Atra(n2) > 0 Then
Tab_Atra(n1) = -1
Else
Tab_Atra(n1) = Tab_Atra(n2) - 1
' If Tab_Atra(n1) < MAIOR_ATR Then MAIOR_ATR = Tab_Atra(n1)
End If
End If
Next
Next
end Function
Public Declare Sub Statistics Lib _
"D:\planilhas\Statistics_1.0.dll" _
(ByRef Result As Long, _
ByVal Cq As Long, ByVal CT As Long, ByVal Lt As Long, ByRef Tab_Atra As Long)
my excel is 32bit so I have to use the long one that is the size of the int of O2 Call Statistics(Sort(1, 1), cq, Ct, Lt, Tab_Atra(1, 1))
I used (1.1) because base1 use in vba, if base 0 would be (0,0)I personally would like to see Basic evolve from C style arrays ( please, give me slicing or cross section of arrays..
int n0,n1
dim L, C
L=3
c=4
redim int Arr2(L)
redim int Arr1(c)
for n0=1 to l
Arr2(n0)=getmemory c*sizeof int
next
for n0=1 to 3
@Arr1= Arr2(n0)
for n1=1 to c
Arr1(n1)=n1+n0*10
next
next
@Arr1=arr2(2)
print arr1(1)
how would this array of arrays of characters ?'11:10 31/05/2018
'ARRAY OF ARRAYS USING STRINGS
'CREATE ARRAY FOR INTs
======================
string sy[100] 'STRING BUFFERS
int i
for i=1 to 100
sy[i]=nuls 50*sizeof int 'dim int sx[50]
next
'
'ACCESS ARRAY (USING INDEXBASE 1)
=================================
macro aa int* (va,ix,iy)
@va=strptr sy(iy)+(ix)*4-4
end macro
'TESTS:
=======
aa(2,3)=42
aa(20,30)=100
print aa(2,3)*aa(20,30)
'11:10 31/05/2018
'DYNAMIC 2D array
int sy=100, sx=50
redim int a(sy*sx)
'
'ACCESS ARRAY (USING INDEXBASE 1)
=================================
macro aa(iy,ix)
a( ( (iy)-1)*sx + (ix) )
end macro
'TESTS:
=======
#show aa(2,3)=42
aa(20,30)=100
print aa(2,3)*aa(20,30)
A regular 2D dynamic array is simpler:Code: [Select]'11:10 31/05/2018
'DYNAMIC 2D array
int sy=100, sx=50
redim int a(sy*sx)
'
'ACCESS ARRAY (USING INDEXBASE 1)
=================================
macro aa(iy,ix)
a( ( (iy)-1)*sx + (ix) )
end macro
'TESTS:
=======
#show aa(2,3)=42
aa(20,30)=100
print aa(2,3)*aa(20,30)
dcl a(100) fixed bin(31);
dcl b(10,10) fixed bin(31) defined(a((1sub-1) * hbound(b,1) + 2sub));
Now you can just use array b to refer to array a as 2D array (like your macro, but compiler can do error checking). dcl a(100) fixed bin(31);
dcl c(10,10) fixed bin(31) based(addr(a));
dcl p ptr;
dcl e(10,10) fixed bin(31) based(p);
allocate e;
I like the concept of a based variable. It removes the need for ugly C-style casting and let compiler do the math. dcl a(11) float init(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0);
dcl b(10,10) defined a(1sub*(1sub=2sub) + (1sub^=2sub)*hbound(a)) float;
Guess what it does?
Unfortunately Eduardo, i only use indices from 0 upwards, i have never encounter
or use arrays with negative indices. What is the purpose of your usage ?
What fields of work that would use negative indices in arrays?
Best that you ask Charles on this matter.