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
//----------------------------------------------------------------------------//
Browsing empty arrays
-
- Posts: 16
- Joined: Fri Apr 28, 2006 4:09 pm
- Location: Australia
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Browsing empty arrays
@ 1, 1 LISTBOX oBrw FIELDS IF( EMPTY( aData ), "", aData[ oBrw:nAt ][ 1 ] ),;George Trojan wrote:@ 1, 1 LISTBOX oBrw FIELDS aData[ oBrw:nAt ][ 1 ],;
And so on.
EMG
-
- Posts: 16
- Joined: Fri Apr 28, 2006 4:09 pm
- Location: Australia
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
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
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
You have to put an IF() for each browse column: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]),'') ;
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]) ;
EMG
-
- Posts: 16
- Joined: Fri Apr 28, 2006 4:09 pm
- Location: Australia
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
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
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
This is a working sample:
EMG
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
-
- Posts: 16
- Joined: Fri Apr 28, 2006 4:09 pm
- Location: Australia
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
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