Browsing empty arrays

Browsing empty arrays

Postby George Trojan » Sun Apr 30, 2006 12:10 pm

The below works as required; however, when aData is an empty array it comes up with 1132 Error, Bound error:array access. This doesn't happen with the 16-bit FW27. Advice would be appreciated as to how this is dealt with using FWH

Thanks


// Browsing a two dimensions array with FiveWin powerfull TWBrowse

#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

local oDlg, oBrw
local aData := { { "1", "Cliente", "=", "123456" },;
{ "2", "Direccion", "$", "Spain" },;
{ "3", "Telefono", "<>", "889977665" } }

SET _3DLOOK ON

DEFINE DIALOG oDlg FROM 2, 2 TO 20, 50
@ 1, 1 LISTBOX oBrw FIELDS aData[ oBrw:nAt ][ 1 ],;
aData[ oBrw:nAt ][ 2 ],;
aData[ oBrw:nAt ][ 3 ],;
aData[ oBrw:nAt ][ 4 ] OF oDlg ;
SIZE 150, 100 HEADERS "One", "Two", "Three", "Four"

oBrw:SetArray( aData )

@ 10, 9 BUTTON "&End" OF oDlg ACTION oDlg:End()

ACTIVATE DIALOG oDlg CENTERED

return nil

//----------------------------------------------------------------------------//
George Trojan
 
Posts: 16
Joined: Fri Apr 28, 2006 4:09 pm
Location: Australia

Re: Browsing empty arrays

Postby Enrico Maria Giordano » Sun Apr 30, 2006 2:22 pm

George Trojan wrote:@ 1, 1 LISTBOX oBrw FIELDS aData[ oBrw:nAt ][ 1 ],;


@ 1, 1 LISTBOX oBrw FIELDS IF( EMPTY( aData ), "", aData[ oBrw:nAt ][ 1 ] ),;

And so on.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby George Trojan » Mon May 01, 2006 11:51 am

Thanks for your response. That works in the sample; howevere, it doesn't work in the below:

REDEFINE LISTBOX oBrwOrdr ;
FIELDS aOrder[oBrwOrdr:nAt][1],aOrder[oBrwOrdr:nAt][2],;
aOrder[oBrwOrdr:nAt][3],aOrder[oBrwOrdr:nAt][4],aOrder[oBrwOrdr:nAt][5],aOrder[oBrwOrdr:nAt][6] ;
ID 110 OF oAddOrder ;
COLSIZES 415,47,60,60,60,60 HEADERS "Product Description","Qty","Price","Sub-Total","Sub-GST","Total" ;
COLOR CLR_BLUE,CLR_WHITE ;
FONT oFont ;
UPDATE

If when the array is empty, I can assign {''} to aOrder ie.

aOrder:={''} but we get a blank line in the browse and we start with an element in the array. Declaring aOrder:={} and the above works in 16bit FW. I have tried various combinations of ...FIELDS IIF(empty(aOrder),... as below:

FIELDS IIF(!empty(aOrder),(aOrder[oBrwOrdr:nAt][1],aOrder[oBrwOrdr:nAt][2],;
aOrder[oBrwOrdr:nAt][3],aOrder[oBrwOrdr:nAt][4],aOrder[oBrwOrdr:nAt][5],aOrder[oBrwOrdr:nAt][6]),'') ;

I always get the "bound error, array access". Thanks for your asistance/advice.

Regards
George Trojan
 
Posts: 16
Joined: Fri Apr 28, 2006 4:09 pm
Location: Australia

Postby Enrico Maria Giordano » Mon May 01, 2006 12:43 pm

George Trojan wrote:FIELDS IIF(!empty(aOrder),(aOrder[oBrwOrdr:nAt][1],aOrder[oBrwOrdr:nAt][2],;
aOrder[oBrwOrdr:nAt][3],aOrder[oBrwOrdr:nAt][4],aOrder[oBrwOrdr:nAt][5],aOrder[oBrwOrdr:nAt][6]),'') ;


You have to put an IF() for each browse column:

Code: Select all  Expand view
FIELDS IIF(!empty(aOrder), "", aOrder[oBrwOrdr:nAt][1]),;
       IIF(!empty(aOrder), "", aOrder[oBrwOrdr:nAt][2]),;
       IIF(!empty(aOrder), "", aOrder[oBrwOrdr:nAt][3]),;
       IIF(!empty(aOrder), "", aOrder[oBrwOrdr:nAt][4]),;
       IIF(!empty(aOrder), "", aOrder[oBrwOrdr:nAt][5]),;
       IIF(!empty(aOrder), "", aOrder[oBrwOrdr:nAt][6]) ;


Or something similar.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby George Trojan » Mon May 01, 2006 1:04 pm

Tried

FIELDS IIF(!empty(aOrder),aOrder[oBrwOrdr:nAt][1],''),IIF(!empty(aOrder),aOrder[oBrwOrdr:nAt][2],''),;
IIF(!empty(aOrder),aOrder[oBrwOrdr:nAt][3],''),IIF(!empty(aOrder),aOrder[oBrwOrdr:nAt][4],''),;
IIF(!empty(aOrder),aOrder[oBrwOrdr:nAt][5],''),IIF(!empty(aOrder),aOrder[oBrwOrdr:nAt][6],'') ;

still get the same error, the only way I can get it to work is to have a 'blank' element in the array ie. aOrder:={'','','','','',''}

Thanks
George Trojan
 
Posts: 16
Joined: Fri Apr 28, 2006 4:09 pm
Location: Australia

Postby John » Mon May 01, 2006 1:37 pm

George,

i had the same problem and just added an empty array to the browser if there is no data present.

Something like: aadd(aData, { "", "", "", "" })

Regards,

John.
John
 
Posts: 67
Joined: Mon Dec 26, 2005 7:44 am
Location: The Netherlands

Postby Enrico Maria Giordano » Mon May 01, 2006 1:40 pm

This is a working sample:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oWnd, oBrw

    LOCAL aArray := { { "Test1_1", "Test1_2" },;
                      { "Test2_1", "Test2_2" },;
                      { "Test3_1", "Test3_2" } }

    LOCAL nCur := 1

    aArray = {}

    DEFINE WINDOW oWnd;
           TITLE "Browsing array"

    @ 0, 0 LISTBOX oBrw FIELDS IF( EMPTY( aArray ), "", aArray[ nCur, 1 ] ),;
                               IF( EMPTY( aArray ), "", aArray[ nCur, 2 ] );
           SIZE 200, 200;
           HEADERS "Test1", "Test2"

    oBrw:bLogicLen = { || Len( aArray ) }
    oBrw:bGoTop    = { || nCur := 1 }
    oBrw:bGoBottom = { || nCur := Len( aArray ) }
    oBrw:bSkip     = { | nSkip | Skipper( aArray, @nCur, nSkip ) }
    oBrw:cAlias    = "ARRAY"

    oBrw:SetFocus()

    ACTIVATE WINDOW oWnd

    RETURN NIL


STATIC FUNCTION SKIPPER( aArray, nCur, nSkip )

    LOCAL nOld := nCur

    nCur += nSkip

    IF nCur > LEN( aArray ); nCur = LEN( aArray ); ENDIF
    IF nCur < 1; nCur = 1; ENDIF

    RETURN nCur - nOld


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby George Trojan » Mon May 01, 2006 1:44 pm

Thanks John, I was trying to avoid having an element in the array at the beginning. Think I may have a solution, do as you suggest and then:

oAddOrder:bStart:={| |aSize(aOrder,0)}

this avoids the array error and starts the browse with an empty array. I was trying to maintain code compatibility between FW and FWH.

Thanks
George Trojan
 
Posts: 16
Joined: Fri Apr 28, 2006 4:09 pm
Location: Australia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 63 guests