Page 1 of 1

Xbrowse : oBrw:ToArray (How to do it)

Posted: Wed Apr 12, 2023 10:06 am
by Marc Venken
Xbrowse has several options to export data (dbf/csv/exel) but how to put them into a array in memory ?

xbrowser ( hData[ "data" ] ) COLUMNS "productid", "model" setup ( oBrw:cHeaders := {"productid","model"}, oBrw:bRClicked := { |r,c,f,o| o:ToDbf( "download.dbf" ) } )

This xbrowse (from a jSon Hash) will create a dbf with the data that I need. I want in a empty(array) the values of only the productid's for later processing.

Re: Xbrowse : oBrw:ToArray (How to do it)

Posted: Wed Apr 12, 2023 10:40 am
by nageswaragunupudi
Do you want something like oBrw:ToArray() ?

Re: Xbrowse : oBrw:ToArray (How to do it)

Posted: Wed Apr 12, 2023 10:59 am
by Marc Venken
Yes,

I use Xbrowser to read complex Json data and with some finetuning I narrow the complex data to 2 fields that I need. I see them in Xbrowse but with my skills i'm not able to put the into a array for further use.

aData = oBrw:ToArray("productid")

maybe also multy array

aData = oBrw:ToArray("productid,model")

Re: Xbrowse : oBrw:ToArray (How to do it)

Posted: Wed Apr 12, 2023 11:05 am
by Marc Venken
I need the productid _ into a other database for references...
With the array I do a simple for next loop

I think we can not do something like this (funny code, but you know what I mean, i hope)


for i = 1 to len(oBrw:adata) // like to process all rows in the Browse
cCode = oBrw:productid(I) // I will process step by step
seek cCode ....
next

Re: Xbrowse : oBrw:ToArray (How to do it)

Posted: Wed Apr 12, 2023 1:20 pm
by Marc Venken
Mr. Rao,

I can do

oBrw:todbf() and then a fw_dbftoarr giving the result I need. No extra code needed in Xbrowse...

Re: Xbrowse : oBrw:ToArray (How to do it)

Posted: Wed Apr 12, 2023 2:16 pm
by nageswaragunupudi

Code: Select all | Expand

function XbrToArray( Self, aCols )

   local aData    := {}
   local nRows    := ::nLen
   local nRow, bm

   if nRows > 0
      if aCols == nil
         aCols    := ::GetVisibleCols()
      else
         aCols    := { |o,i| aCols[ i ] := ::oCol( i ) }
      endif

      aData       := Array( nRows, Len( aCols ) )

      bm          := ::BookMark
      Eval( ::bGoTop, Self )

      for nRow := 1 to nRows
         AEval( aCols, { |o,i| aData[ nRow, i ] := o:Value } )
         Eval( ::bSkip, 1 )
      next

      ::BookMark  := bm

   endif

return aData
 
Usage:

Code: Select all | Expand

aData := XbrToArray( oBrw, [ aCols ] )
 

Re: Xbrowse : oBrw:ToArray (How to do it)

Posted: Wed Apr 12, 2023 2:56 pm
by Marc Venken
I get folowing error when using it in Xbrowser(). My call to rClicked is wrong so to see

xbrowser ( hData[ "data" ] ) COLUMNS "productid", "model" setup ( oBrw:cHeaders := {"productid","model"}, oBrw:bRClicked := { |r,c,f,oBrw| aResult := XbrToArray( oBrw, [ aCols ] ) } )


errorline =
aData := Array( nRows, Len( aCols ) )


Error description: Error BASE/1111 Argument error: LEN
Args:
[ 1] = B {|| ... }

Stack Calls
===========
Called from: => LEN( 0 )
Called from: fiveapi.prg => XBRTOARRAY( 679 )

Re: Xbrowse : oBrw:ToArray (How to do it)

Posted: Thu Apr 13, 2023 2:06 am
by nageswaragunupudi
While showing syntax, we enclose some parameters in square brackets to inform the programmer that these parameters are optional. Not at all that you should use the square brackets in real usage.

NOT

Code: Select all | Expand

oBrw:bRClicked := { |r,c,f,oBrw| aResult := XbrToArray( oBrw, [ aCols ] )
SHOULD BE

Code: Select all | Expand

oBrw:bRClicked := { |r,c,f,oBrw| aResult := XbrToArray( oBrw )

Re: Xbrowse : oBrw:ToArray (How to do it)

Posted: Thu Apr 13, 2023 7:24 am
by Marc Venken
Thanks for the clarification !!

I tried to add a col to the function

oBrw:bRClicked := { |r,c,f,oBrw| aResult := XbrToArray( oBrw, [ aCols ] )

How does the passing aCols look like ?

{1,2}
{"ColName1","Colname2"}

these don't work. When I look in the function and aCols = NIL, it is filled with a Multidim. array from : GetVisibleCols()
SO it will be not a simple array to pass ?

Sorry, but sometimes I need to go back to basics :oops: :oops:

Re: Xbrowse : oBrw:ToArray (How to do it)

Posted: Thu Apr 13, 2023 10:43 am
by nageswaragunupudi
For example, if we are browsing customer.dbf

Code: Select all | Expand

XbrToArray( oBrw. { "FIRST", "CITY", "SALARY" }
where FIRST, CITY, SALARY are headers of the required columns.

Re: Xbrowse : oBrw:ToArray (How to do it)

Posted: Thu Apr 13, 2023 2:03 pm
by Marc Venken
nageswaragunupudi wrote:

Code: Select all | Expand

function XbrToArray( Self, aCols )

   local aData    := {}
   local nRows    := ::nLen
   local nRow, bm

   if nRows > 0
      if aCols == nil
         aCols    := ::GetVisibleCols()
      else
         aCols    := { |o,i| aCols[ i ] := ::oCol( i ) }
      endif

      aData       := Array( nRows, Len( aCols ) )

      bm          := ::BookMark
      Eval( ::bGoTop, Self )

      for nRow := 1 to nRows
         AEval( aCols, { |o,i| aData[ nRow, i ] := o:Value } )
         Eval( ::bSkip, 1 )
      next

      ::BookMark  := bm

   endif

return aData
 
Usage:

Code: Select all | Expand

aData := XbrToArray( oBrw, [ aCols ] )
 
I found it. In the function this code should be there : (From a other post of Mr. Rao)

Code: Select all | Expand

      if aCols == nil
         aCols  := ::GetVisibleCols()
      else
         AEval( aCols, { |o,i| aCols[ i ] := ::oCol( o ) } )
      endif
 
Now it works

Re: Xbrowse : oBrw:ToArray (How to do it)

Posted: Wed Nov 15, 2023 8:40 pm
by sirotoca
hola
soy nuevo en esto
un señor me vendía antes hasta que me dio esta actualización con este error

esto sale y dice cerrar
Stack Calls
===========
Called from: => LEN( 0 )
Called from: a_tc.prg => TCAMBIOSBS( 342 )
Called from: c_todo.prg => C_TODO( 57 )
Called from: siscont.prg => (b)MENUPP( 669 )
Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE( 1023 )
Called from: siscont.prg => MENUPP( 669 )
Called from: siscont.prg => MAIN( 509 )


en el log esta todo esto


Application
===========
Path and name: C:\Siscont2\siscont1.exe (32 bits)
Size: 6,800,896 bytes
Compiler version: Harbour 3.2.0dev (r1703231115)
FiveWin version: FWH 17.12
C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
Windows version: 6.2, Build 9200

Time from start: 0 hours 0 mins 22 secs
Error occurred at: 15/11/2023, 14:36:04
Error description: Error BASE/1111 Argument error: LEN
Args:
[ 1] = U

Stack Calls
===========
Called from: => LEN( 0 )
Called from: a_tc.prg => TCAMBIOSBS( 342 )
Called from: c_todo.prg => C_TODO( 57 )
Called from: siscont.prg => (b)MENUPP( 669 )
Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE( 1023 )
Called from: siscont.prg => MENUPP( 669 )
Called from: siscont.prg => MAIN( 509 )

System
======
CPU type: Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz 2394 Mhz
Hardware memory: 16296 megs

Free System resources: 90 %
GDI resources: 90 %
User resources: 90 %

Windows total applications running: 3
1 ,
2 , C:\Siscont2\siscont1.exe
3 GDI+ Window (siscont1.exe), C:\WINDOWS\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.19041.2251_none_d9513b1fe1046f

Variables in use
================
Procedure Type Value
==========================
LEN
Param 1: O Class: ERROR
TCAMBIOSBS
Param 1: U
Local 1: U
Local 2: U
C_TODO
Param 1: U
Param 2: U
Param 3: U
Param 4: D 15/11/2023
Local 1: U
(b)MENUPP
Param 1: O Class: TMDIFRAME
Local 1: U
Local 2: U
Local 3: U
Local 4: U
Local 5: U
Local 6: U
Local 7: U
Local 8: U
Local 9: U
Local 10: A Len: 4
Local 11: A Len: 31
Local 12: U
Local 13: A Len: 4
Local 14: A Len: 31
Local 15: U
TMDIFRAME:ACTIVATE
Param 1: O Class: TMDIFRAME
MENUPP
Param 1: C "MAXIMIZED"
Param 2: U
Param 3: U
Param 4: U
Param 5: U
Param 6: U
Param 7: U
Param 8: B {|| ... }
Param 9: U
Param 10: U
Param 11: U
Param 12: U
Param 13: U
Param 14: U
Param 15: U
Param 16: U
Param 17: U
Param 18: U
Param 19: U
Param 20: L .F.
Local 1: O Class: TMDIFRAME
Local 2: U
Local 3: U
MAIN
Local 1: O Class: TBITMAP
Local 2: O Class: TICON
Local 3: U

Linked RDDs
===========
DBF
DBFFPT
DBFBLOB
DBFCDX
DBFNTX

DataBases in use
================

1: => EMP RddName: DBFNTX
==============================
RecNo RecCount BOF EOF
1 1 .F. .F.

Indexes in use TagName

Relations in use

Classes in use:
===============
1 ERROR
2 HBCLASS
3 HBOBJECT
4 TFONT
5 WIN_OLEAUTO
6 TOLEAUTO
7 TWINDOW
8 TDIALOG
9 TBRUSH
10 TCONTROL
11 TICON
12 TMULTIGET
13 TBUTTON
14 TRECT
15 TSAY
16 TGET
17 GET
18 TCLIPGET
19 TREG32
20 TCURSOR
21 TBITMAP
22 TMDIFRAME
23 TMENU
24 TMENUITEM
25 TMDICLIENT
26 TBAR
27 TBTNBMP
28 TMSGBAR
29 TMSGITEM
30 TTIMER
31 TSTRUCT

Memory Analysis
===============
557 Static variables

Dynamic memory consume:
Actual Value: 2359296 bytes
Highest Value: 2359296 bytes

Re: Xbrowse : oBrw:ToArray (How to do it)

Posted: Wed Nov 15, 2023 9:02 pm
by Silvio.Falconi
Search on forum my procedure to create array

Re: Xbrowse : oBrw:ToArray (How to do it)

Posted: Thu Nov 16, 2023 2:52 am
by nageswaragunupudi
From version 23.04 onwards XBrowse has a method ToArray()
We can directly use

Code: Select all | Expand

aData := oBrw:ToArray()
// or
aData := oBrw:ToArray( aCols )