How to extract array from array browser

This forum is for eXpress++ general support.
Message
Author
Janko
Posts: 111
Joined: Sat Mar 20, 2010 8:36 am
Location: Cerklje

How to extract array from array browser

#1 Post by Janko »

Dear Roger,

I have an array browser with 38 visabel rows and 15 visable columns. Array can be bigger or smaller than 38x 15. User can filter out some columns or some rows to obtain tailored table. I want to offer an option to export this, last designed table to .xslx, so it is neccesary to extract data that could be displayed. This table could be bigger or smaller than what is visable on screen.

I've tried with oBrowse:columnCount() to determine number of displayabe columns, but I could not find proper function to extract number of displayable rows.

At the end: where to extract data from? I'd prefer to do it from oBrowse:column object, but I am not sure this is good idea.

Can you help me with a hint?

Best regards
JAnko

Zdeno Bielik
Posts: 147
Joined: Thu Jan 28, 2010 9:24 am
Location: Nitra, Slovakia
Contact:

Re: How to extract array from array browser

#2 Post by Zdeno Bielik »

Hi,

try look into variable oBrowse:DataSource, if it contains, what you want/need.
Or try export only needed columns in MyExport routine.

HTH,
Zdeno

Code: Select all

@ nRow, nCol DCPUSHBUTTON CAPTION 'Export' ... ;
           ACTION {|| MyExport( oBrowse ) } ...


****************
Function MyExport( oBrowse )
*****************

Local aSource := oBrowse:DataSource
Local i, nRows := Len( oBrowse:DataSource ), nCols := oBrowse:ColCount
Local aExport := {}

wtf oBrowse, aSource, nRows, nCols

For i := 1 To nRows
*     If "any conditions..."
    AAdd( aExport, aSource[i] )
*     EndIf
Next

wtf aExport

*  and save array aSource or aExport like XLS...

Return ( NIL )

*

Janko
Posts: 111
Joined: Sat Mar 20, 2010 8:36 am
Location: Cerklje

Re: How to extract array from array browser

#3 Post by Janko »

Zdeno,

thanks for your answer. I have available data source. It is original array, which is bein browsed. But user can change ordinal position of column, can delete a column, can reveal column(s)..... And of course can filter rows, can calculate indexes, averages ...... and the final design is shown, but can be bigger or smaller than screen itself. So, I normaly loose the trail of all moves and filters.

I think that it should be possible to retrive data fo each column from column object.

Your solution is not good for me.

Maybe someone has different idea?

Best regards
JAnko

Janko
Posts: 111
Joined: Sat Mar 20, 2010 8:36 am
Location: Cerklje

Re: How to extract array from array browser

#4 Post by Janko »

I found the solution:

each column object contains oBrowse:GetColumn(i):arrayPointer which points to data array column.

I have to discover efects of FILTER clause in array browse.


Best regards
JAnko

User avatar
Tom
Posts: 1175
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: How to extract array from array browser

#5 Post by Tom »

Code: Select all

FOR n := 1 TO oBrowse:RowCount
  FOR i := 1 TO oBrowse:ColCount
    ? oBrowse:GetColumn(i):DataArea:GetCell(n) 
  NEXT
NEXT
To be honest, this won't work good, since it shows all data from row 1 to the number of rows you see on the screen. You must find the number of the first row on the screen. oColumn:DataArea:CellFromPos(<aPos>) will give you the row number for the cell at "aPos". If aPos is the position of the first record in this column, you will get the right number.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Janko
Posts: 111
Joined: Sat Mar 20, 2010 8:36 am
Location: Cerklje

Re: How to extract array from array browser

#6 Post by Janko »

Tom,

I did it in this way:

Code: Select all


LOCAL i,j , nmaxrow, nmaxcol , arr 
Local aCol:=array(obr:ColCount)

nMaxCol:=obr:Colcount
nMaxRow:= len(obr:GetColumn(1):dataArea:cargo[8]   )
nPointer:= obr:getColumn(1):arrayPointer
arr:=array(nMaxRow, nMaxCol)

// obr:=oBrowse
nMaxCol:=obr:Colcount
nMaxRow:= len(obr:GetColumn(1):dataArea:cargo[8]   )
arr:=array(nMaxRow, nMaxCol)

for i:=1 to obr:ColCount
 aCol[i]:=obr:GetColumn(i):arrayPointer           // aCol is array of numbers that point to dataSource row numbers 
next i
 
for i:=1 to nMaxcol
	for j:= 1 to nMaxRow
		 arr[j,i]:= obr:DataSource[j,aCol[i]
	next j
next i
dc_arrayview(arr)
          
But using FILTER clause in oBrowse, which filters out certain rows has no influence to DataSource array.

What I would like to find out is where in column object are written displayable data (without those that are eliminated with FILTER)?

Any hint appreciated.

Best regards
JAnko

User avatar
rdonnay
Site Admin
Posts: 4733
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: How to extract array from array browser

#7 Post by rdonnay »

What I would like to find out is where in column object are written displayable data (without those that are eliminated with FILTER)?
Please clarify what it is that you want. I don't understand.
The eXpress train is coming - and it has more cars.

Janko
Posts: 111
Joined: Sat Mar 20, 2010 8:36 am
Location: Cerklje

Re: How to extract array from array browser

#8 Post by Janko »

Roger,

I have an array of data dim 120 rows and 40 columns. Display can show 38 rows and 15 columns. rest of the array can be scrolled in and out.
User can select some columns and delete them with :delColumn().

As well DCBROWSE option allows FILTER clause that eliminates from view certain rows. So, final displayable array can contain 50 rows and 20 columns.
My intention is to export to .xlsx this final (displayable) array.

I can find links among displayed columns and datasource array using aCol:=obr:GetColumn(i):arrayPointer.
But I do not know which rows were filtered using FILTER clause in oBrowse.

I hope I was clear enough.

Best regards
JAnko

User avatar
rdonnay
Site Admin
Posts: 4733
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: How to extract array from array browser

#9 Post by rdonnay »

Show me what your FILTER clause looks like.

Also, what method do you intend to use to export to XLS?

If you are using DC_Array2Excel(), then it would be best to create a new array from the browse array.
The eXpress train is coming - and it has more cars.

User avatar
rdonnay
Site Admin
Posts: 4733
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: How to extract array from array browser

#10 Post by rdonnay »

I think this is what you want. Here is a sample program:

Code: Select all

#INCLUDE "dcdialog.CH"

FUNCTION Main()

LOCAL GetList[0], aDir, i, oBrowse

DC_ChDir('C:\windows\system32')

aDir := Directory()

@ 0,0 DCBROWSE oBrowse DATA aDir SIZE 100,20 ;
      FILTER {|a|a[2]>100000}

FOR i := 1 TO 10
  DCBROWSECOL ELEMENT i HEADER Alltrim(Str(i)) WIDTH 10 PARENT oBrowse
NEXT

@ 21,0 DCPUSHBUTTON CAPTION 'Export' SIZE 10 ;
   ACTION {||ExportData(oBrowse)}

DCREAD GUI FIT TITLE 'Array Export Test'

RETURN nil

* -----------

STATIC FUNCTION ExportData(oBrowse)

LOCAL aData := {}, i, lDone := .f.

oBrowse:lockUpdate(.t.)

oBrowse:hitBottomBlock := {||lDone := .t.}

oBrowse:goTop()
oBrowse:forceStable()

DO WHILE !lDone

  AAdd(aData,Array(oBrowse:colCount))
  FOR i:= 1 TO oBrowse:colCount
    ATail(aData)[i] := Eval(oBrowse:getColumn(i):dataLink)
  NEXT

  oBrowse:down()
  oBrowse:forceStable()

ENDDO

oBrowse:goTop()
oBrowse:forceStable()
oBrowse:lockUpdate(.f.)

wtf aData

RETURN nil
The eXpress train is coming - and it has more cars.

Post Reply