Home > Archive > Clipper > July 2007 > Tbrowse on two dimensional array
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Tbrowse on two dimensional array
|
|
|
| Hello
I like to make a Tbrowse on a two dimensional array. But I cant find out how to make a correct Skip function (see SkipIt)
Thanks in advance for any help.
Otto
Here my code:
#define MAXLEN 8
STATIC FUNCTION GetMatrix(mode)
Local l,c,ob,col,nKey
Local aMatrix[8][8]
for l = 1 to 8
for c = 1 to 8
aMatrix[l][c] := "000"
next
next
// TBrowse object for values
ob := TBrowseNew( 1, 1, 10, 40 )
//
// aMatrix is passed by reference
ob:skipBlock := {|x| SkipIt(x, @aMatrix)}
ob:goTopBlock := {|| aMatrix := 1}
ob:goBottomBlock := {|| aMatrix := MAXLEN}
// TBColumn Object
col := TBColumnNew("A",{|| aMatrix[1]})
ob:addColumn( col )
col := TBColumnNew("B",{|| aMatrix[2]})
ob:addColumn( col )
col := TBColumnNew("C",{|| aMatrix[3]})
ob:addColumn( col )
col := TBColumnNew("D",{|| aMatrix[4]})
ob:addColumn( col )
col := TBColumnNew("E",{|| aMatrix[5]})
ob:addColumn( col )
col := TBColumnNew("F",{|| aMatrix[6]})
ob:addColumn( col )
col := TBColumnNew("G",{|| aMatrix[7]})
ob:addColumn( col )
col := TBColumnNew("H",{|| aMatrix[8]})
ob:addColumn( col )
While nKey # K_ESC
While(!ob:stabilize())
nKey := Inkey()
if (nKey != 0)
exit
end
end
Inkey(0)
end
Return nil
STATIC FUNCTION SkipIt(nRequest, nSubscript)
Local k := 0
if nrequest == 0 // schow current
k := 0
elseif nrequest > 0 // skip forward
if nrequest < (MAXLEN - nsubscript)
k := nrequest
else
k := MAXLEN - nsubscript
endif
elseif nrequest < 0 // skip backwards
if nrequest < (1 - nsubscript)
k := 1 - nsubscript
else
k := nrequest
endif
endif
// position in the proper element
nsubscript += k
Return(k)
| |
|
|
Hello,
I used this kind of code ( Clipper 5.3b ... 1998 )
Note: mmm is a private two dimensional array passed by reference (@)
and lin_max is a private variable which contains the actual number of
lines of the array
..........................................
function tab_par(inirow,inicol,endrow,endcol,i_a,
tex_tit,mmm)
local i,cycle,contor,cul_vec,este_modif:=.f.
local ncit,o,coloana,ecrjos,ecrtab,ecrins
private nrow,nskip
ncit:=0
nrow:=1
......................
o:=TBrowseNew(inirow+1,inicol+1,endrow-1,endcol-1)
o:headSep:=chr(196)
o:colSep:=' '+chr(179)+' '
o:skipBlock:={|nskip| nskip:=skipTable(nskip,@nrow,lin_max)}
o:goTopBlock:={|| nrow:=1}
o:goBottomBlock :={|| nrow:=lin_max}
o:colorSpec := cultab
if i_a = 'P'
coloana:=TBColumnNew ('Denumire',{|| mmm[nrow,1]})
coloana:defcolor:={1,2}
o:addColumn(coloana)
coloana:=TBColumnNew ('Procent',{|| if(mmm[nrow,
2]<>0.00,str(mmm[nrow,2],6,2),space(6))})
coloana:defcolor:={1,2}
o:addColumn(coloana)
else
...........................
endif
o:colpos:=2
cycle:=.t.
do while cycle
o:forcestable()
if o:hittop .or. o:hitbottom
tone(600,2)
endif
ncit := inkey(0)
do case
case ncit == K_DOWN
o:down()
case ncit == K_UP
o:up()
case ncit == K_PGDN
o:pageDown()
case ncit == K_PGUP
o:pageUp()
case ncit == K_CTRL_PGUP
o:goTop()
case ncit == K_CTRL_PGDN
o:goBottom()
case ncit == K_RIGHT
o:right()
case ncit == K_LEFT
o:left()
case ncit == K_HOME
o:home()
case ncit == K_END
o:end()
case ncit == K_CTRL_LEFT
o:panLeft()
case ncit == K_CTRL_RIGHT
o:panRight()
case ncit == K_CTRL_HOME
o:panHome()
case ncit == K_CTRL_END
o:panEnd()
case ncit == K_ESC
cycle:=.f.
case ncit>31 .and. ncit<127
if o:colpos = 1
o:right()
loop
endif
keyboard chr(ncit)
setcursor(1)
if i_a = 'P'
@ row(),col() get mmm[nrow,2] pict '999.99' color
cul_cit ;
valid mmm[nrow,2] >= 0.00
else
...................
endif
read
setcursor(0)
if updated() .and. i_a='D' .and. o:colpos=2
este_modif:=.t.
endif
o:refreshcurrent()
if nrow < lin_max
o:down()
endif
endcase
enddo
............................
return (este_modif)
static function SkipTable(n,ar,mr)
local i
i:=0
if n > 0
do while i<n
ar:=ar+1
if ar > mr
ar:=ar-1
exit
endif
i:=i+1
enddo
elseif n<0
do while i>n
ar:=ar-1
if ar=0
ar:=ar+1
exit
endif
i:=i-1
enddo
endif
return (i)
...................................
Ella
| |
|
| On Sun, 08 Jul 2007 03:14:20 -0700, SEI <seisoft@citromail.hu> wrote:
Hello
Many thanks for your help. In the between time I adapted a sample. Look like this:
nRow := 1
// TBrowse object for values
ob := TBrowseNew( 0,0,8,40 )
ob:ColorSpec := c_cadre2_t+"/"+c_cadre2_f+","+c_get_t+"/"+c_get_f+","+ ;
c_date+"/"+c_cadre2_f+","+c_vrai+"/"+c_cadre2_f+","+ ;
c_chiffre+"/"+c_cadre2_f+","+c_texte+"/"+c_cadre2_f
ob:headSep := "-"
ob:footSep := "-"
ob:colSep := "|"
ob:skipBlock := { |nSkip| nSkip := aSkipIt( aMatrix, nRow, nSkip ),nRow += nSkip,nSkip}
ob:goTopBlock := { || nRow := 1 }
ob:goBottomBlock := { || nRow := LEN( aMatrix ) }
for l := 1 TO Len( aMatrix[1] )
ob:addColumn( TBColumnNew( "", ABrowseBlock(aMatrix,l)) )
next
// main key handler loop
do while ( nkey <> K_ESC ) .and. ( nkey <> K_RETURN )
// stabilize the browse and wait for a keystroke
ob:forcestable()
nkey := inkey( 0 )
// process the directional keys
if ob:stable
do case
case ( nkey == K_DOWN )
ob:down()
case ( nkey == K_UP )
ob:up()
case ( nkey == K_RIGHT )
ob:right()
case ( nkey == K_LEFT )
ob:left()
end
end
end
Wclose()
Return nil
STATIC FUNCTION ABrowseBlock( a, x )
// Debug("Buchung",Procname(),Procline(),Str(nRow),Str(x) )
Return ( {|p| IF( Pcount() == 0, a[nRow, x], a[nRow, x] := p ) } )
STATIC FUNCTION ASkipIt( a, nCurrent, nSkip )
if ( nCurrent + nSkip < 1 )
// Would skip past the top...
Return( -nCurrent + 1 )
elseif ( nCurrent + nSkip > LEN( a ) )
// Would skip past the bottom...
Return ( LEN(a) - nCurrent )
end
Return( nSkip )
>
>Hello,
>
>
>I used this kind of code ( Clipper 5.3b ... 1998 )
>
>Note: mmm is a private two dimensional array passed by reference (@)
>and lin_max is a private variable which contains the actual number of
>lines of the array
>
>
>.........................................
>function tab_par(inirow,inicol,endrow,endcol,i_a,
tex_tit,mmm)
>local i,cycle,contor,cul_vec,este_modif:=.f.
>local ncit,o,coloana,ecrjos,ecrtab,ecrins
>private nrow,nskip
>
>ncit:=0
>nrow:=1
>.....................
>o:=TBrowseNew(inirow+1,inicol+1,endrow-1,endcol-1)
>o:headSep:=chr(196)
>o:colSep:=' '+chr(179)+' '
>o:skipBlock:={|nskip| nskip:=skipTable(nskip,@nrow,lin_max)}
>o:goTopBlock:={|| nrow:=1}
>o:goBottomBlock :={|| nrow:=lin_max}
>o:colorSpec := cultab
>
>if i_a = 'P'
> coloana:=TBColumnNew ('Denumire',{|| mmm[nrow,1]})
> coloana:defcolor:={1,2}
> o:addColumn(coloana)
> coloana:=TBColumnNew ('Procent',{|| if(mmm[nrow,
>2]<>0.00,str(mmm[nrow,2],6,2),space(6))})
> coloana:defcolor:={1,2}
> o:addColumn(coloana)
>else
>..........................
>endif
>
>o:colpos:=2
>cycle:=.t.
>
>do while cycle
> o:forcestable()
> if o:hittop .or. o:hitbottom
> tone(600,2)
> endif
> ncit := inkey(0)
> do case
> case ncit == K_DOWN
> o:down()
> case ncit == K_UP
> o:up()
> case ncit == K_PGDN
> o:pageDown()
> case ncit == K_PGUP
> o:pageUp()
> case ncit == K_CTRL_PGUP
> o:goTop()
> case ncit == K_CTRL_PGDN
> o:goBottom()
> case ncit == K_RIGHT
> o:right()
> case ncit == K_LEFT
> o:left()
> case ncit == K_HOME
> o:home()
> case ncit == K_END
> o:end()
> case ncit == K_CTRL_LEFT
> o:panLeft()
> case ncit == K_CTRL_RIGHT
> o:panRight()
> case ncit == K_CTRL_HOME
> o:panHome()
> case ncit == K_CTRL_END
> o:panEnd()
> case ncit == K_ESC
> cycle:=.f.
> case ncit>31 .and. ncit<127
> if o:colpos = 1
> o:right()
> loop
> endif
> keyboard chr(ncit)
> setcursor(1)
> if i_a = 'P'
> @ row(),col() get mmm[nrow,2] pict '999.99' color
>cul_cit ;
> valid mmm[nrow,2] >= 0.00
> else
>..................
> endif
> read
> setcursor(0)
> if updated() .and. i_a='D' .and. o:colpos=2
> este_modif:=.t.
> endif
> o:refreshcurrent()
> if nrow < lin_max
> o:down()
> endif
> endcase
>enddo
>...........................
>return (este_modif)
>
>
>
>static function SkipTable(n,ar,mr)
>local i
> i:=0
> if n > 0
> do while i<n
> ar:=ar+1
> if ar > mr
> ar:=ar-1
> exit
> endif
> i:=i+1
> enddo
> elseif n<0
> do while i>n
> ar:=ar-1
> if ar=0
> ar:=ar+1
> exit
> endif
> i:=i-1
> enddo
> endif
>return (i)
>..................................
>
>
>Ella
| |
|
|
|
|
|
|
|