Xbrowse : oBrw:ToArray (How to do it)

Xbrowse : oBrw:ToArray (How to do it)

Postby Marc Venken » Wed Apr 12, 2023 10:06 am

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.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1426
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

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

Postby nageswaragunupudi » Wed Apr 12, 2023 10:40 am

Do you want something like oBrw:ToArray() ?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

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

Postby Marc Venken » Wed Apr 12, 2023 10:59 am

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")
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1426
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

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

Postby Marc Venken » Wed Apr 12, 2023 11:05 am

I need the productid to scan 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
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1426
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

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

Postby Marc Venken » Wed Apr 12, 2023 1:20 pm

Mr. Rao,

I can do

oBrw:todbf() and then a fw_dbftoarr giving the result I need. No extra code needed in Xbrowse...
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1426
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

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

Postby nageswaragunupudi » Wed Apr 12, 2023 2:16 pm

Code: Select all  Expand view
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 view
aData := XbrToArray( oBrw, [ aCols ] )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

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

Postby Marc Venken » Wed Apr 12, 2023 2:56 pm

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 )
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1426
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

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

Postby nageswaragunupudi » Thu Apr 13, 2023 2:06 am

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 view
oBrw:bRClicked := { |r,c,f,oBrw| aResult := XbrToArray( oBrw, [ aCols ] )


SHOULD BE
Code: Select all  Expand view
oBrw:bRClicked := { |r,c,f,oBrw| aResult := XbrToArray( oBrw )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

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

Postby Marc Venken » Thu Apr 13, 2023 7:24 am

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:
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1426
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

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

Postby nageswaragunupudi » Thu Apr 13, 2023 10:43 am

For example, if we are browsing customer.dbf
Code: Select all  Expand view
XbrToArray( oBrw. { "FIRST", "CITY", "SALARY" }

where FIRST, CITY, SALARY are headers of the required columns.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

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

Postby Marc Venken » Thu Apr 13, 2023 2:03 pm

nageswaragunupudi wrote:
Code: Select all  Expand view
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 view
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 view
     if aCols == nil
         aCols  := ::GetVisibleCols()
      else
         AEval( aCols, { |o,i| aCols[ i ] := ::oCol( o ) } )
      endif
 


Now it works
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1426
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

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

Postby sirotoca » Wed Nov 15, 2023 8:40 pm

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

sirotoca
 
Posts: 2
Joined: Sat Nov 04, 2023 3:09 pm

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

Postby Silvio.Falconi » Wed Nov 15, 2023 9:02 pm

Search on forum my procedure to create array
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

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

Postby nageswaragunupudi » Thu Nov 16, 2023 2:52 am

From version 23.04 onwards XBrowse has a method ToArray()
We can directly use
Code: Select all  Expand view
aData := oBrw:ToArray()
// or
aData := oBrw:ToArray( aCols )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 46 guests