XBrowse ToExcel

XBrowse ToExcel

Postby Gary Woodley » Mon Oct 31, 2011 2:36 pm

Hi,
I have had 2 errors when exporting to excel from an xbrowse.
1. Argument error: ALLTRIM which was called from xbrowse.prg => TXBRWCOLUMN:CLPTEXT(11406)
Original Code:-
Code: Select all  Expand view
if ::bEditValue == nil
      if ::bStrData == nil
         RetVal   := ""
      else
         RetVal   :=  AllTrim(Eval( ::bStrData ))
      endif

This was fixed by:-
Code: Select all  Expand view
 if ::bEditValue == nil
      if ::bStrData == nil
         RetVal   := ""
      else
         RetVal   := Eval( ::bStrData )
        IF Valtype(RetVal) == "N"
            RetVal   := AllTrim(STR(RetVal) )
        ELSEIF Valtype(RetVal) == "C"
            RetVal   := AllTrim(RetVal)            
        ENDIF
      endif


2.Argument error: $ which was called from xbrowse.prg => TXBROWSE:TOEXCEL(6851)
Original Code:-
Code: Select all  Expand view
if ::nDataType != DATATYPE_ARRAY
         DO CASE
             CASE cType == 'N'
                cFormat     := Clp2xlNumPic( oCol:cEditPicture )
                oSheet:Columns( nCol ):NumberFormat := cFormat
                oSheet:Columns( nCol ):HorizontalAlignment := - 4152 //xlRight
   
             CASE cType == 'D'
                if lxlEnglish
                  if ValType( oCol:cEditPicture ) == 'C' .and. Left( oCol:cEditPicture, 1 ) != '@'
                     oSheet:Columns( nCol ):NumberFormat := Lower( oCol:cEditPicture )
                  else
                     oSheet:Columns( nCol ):NumberFormat := Lower( Set( _SET_DATEFORMAT ) )
                  endif
                  oSheet:Columns( nCol ):HorizontalAlignment := - 4152 //xlRight
                endif
             CASE cType $ "LPFM"
                // leave as general format
             OTHERWISE
                if ::nDataType != DATATYPE_ARRAY
                   oSheet:Columns( nCol ):NumberFormat := "@"
                   if ! Empty( oCol:nDataStrAlign )
                      oSheet:Columns( nCol ):HorizontalAlignment := If( oCol:nDataStrAlign == AL_CENTER, -4108, -4152 )
                   endif
                endif
         ENDCASE
      endif

This was fixed by checking if ctype is empty as it seemed a null was being received.:-
Code: Select all  Expand view
if ::nDataType != DATATYPE_ARRAY
         IF!EMPTY(cType)
             DO CASE
             CASE cType == 'N'
                cFormat     := Clp2xlNumPic( oCol:cEditPicture )
                oSheet:Columns( nCol ):NumberFormat := cFormat
                oSheet:Columns( nCol ):HorizontalAlignment := - 4152 //xlRight
   
             CASE cType == 'D'
                if lxlEnglish
                  if ValType( oCol:cEditPicture ) == 'C' .and. Left( oCol:cEditPicture, 1 ) != '@'
                     oSheet:Columns( nCol ):NumberFormat := Lower( oCol:cEditPicture )
                  else
                     oSheet:Columns( nCol ):NumberFormat := Lower( Set( _SET_DATEFORMAT ) )
                  endif
                  oSheet:Columns( nCol ):HorizontalAlignment := - 4152 //xlRight
                endif
             CASE cType $ "LPFM"
                // leave as general format
             OTHERWISE
                if ::nDataType != DATATYPE_ARRAY
                   oSheet:Columns( nCol ):NumberFormat := "@"
                   if ! Empty( oCol:nDataStrAlign )
                      oSheet:Columns( nCol ):HorizontalAlignment := If( oCol:nDataStrAlign == AL_CENTER, -4108, -4152 )
                   endif
                endif
             ENDCASE
         ENDIF
      endif


Could someone review this code to see if the changes are correct and then implement it in future FWH releases

Thanks

Gary
Gary Woodley
 
Posts: 28
Joined: Mon Apr 27, 2009 3:37 pm
Location: Oxford UK

Re: XBrowse ToExcel

Postby nageswaragunupudi » Mon Oct 31, 2011 4:59 pm

1. Argument error: ALLTRIM

As the very name bStrData suggests, the code is expected to be evaluated to a character value. ( b+ "Str" + Data : meaning the data as string ). or nil.

If xBrowse is coded the recommended way, there will "never" be a case where bStrData returning a non-character value or nil.

Direct use of bStrData was deprecated years back. Instead, it has always been recommended to assign the code block to bEditValue and picture clause to cEditPicture. XBrowse internally constructs bStrData.

The code errors out in case of non-standard usage of bStrData and that was intentional.
Regards

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

Re: XBrowse ToExcel

Postby nageswaragunupudi » Mon Oct 31, 2011 5:22 pm

2.Argument error: $ which was called from xbrowse.prg => TXBROWSE:TOEXCEL(6851)

Code: Select all  Expand view
        DO CASE
         CASE Empty( cType ) // inserted now
            // no action
         CASE cType == 'N'
 

We can make the code a bit more tolerant as above.

But it is desirable that cDataType is intialized in all cases except arrays. If the browse is created in the command mode or using aCols parameter in the Set...( functions cDataType is automatically initialzed by xbrowse.
Regards

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


Return to FiveWin for Harbour/xHarbour

Who is online

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