Browsing empty arrays

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

Browsing empty arrays

Post by George Trojan »

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

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

Re: Browsing empty arrays

Post by Enrico Maria Giordano »

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
George Trojan
Posts: 16
Joined: Fri Apr 28, 2006 4:09 pm
Location: Australia

Post by George Trojan »

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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

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

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
George Trojan
Posts: 16
Joined: Fri Apr 28, 2006 4:09 pm
Location: Australia

Post by George Trojan »

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
John
Posts: 67
Joined: Mon Dec 26, 2005 7:44 am
Location: The Netherlands

Post by John »

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.
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

This is a working sample:

Code: Select all

#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
George Trojan
Posts: 16
Joined: Fri Apr 28, 2006 4:09 pm
Location: Australia

Post by George Trojan »

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
Post Reply