xbrowse value of cell is nil

xbrowse value of cell is nil

Postby Rick Lipkin » Tue Sep 21, 2010 6:48 pm

To All

I have a recordset where the field "lastlog" ( Last Login ) could be nil .. instead of xBrowse showing the cell value as nil I would prefer "00/00/0000" ... here is the code :

Code: Select all  Expand view

DEFINE ICON oICO RESOURCE "SCANNER"

DEFINE WINDOW oUser                        ;
      FROM 2,2 to 25,65                    ;
      of oWndMDI                           ;
      TITLE "USERINFO Administrative Browse" ;
      MENU BuildMenu(oRsUser)              ;
      ICON oICO ;
      NOMINIMIZE                           ;
      NOZOOM                               ;
      MDICHILD

@ 0, 0 xBROWSE oBrow of oUser              ;
       RECORDSET oRsUser                   ;
       COLUMNS "USERID",                   ;
               "READ",                     ;
               "WRITE",                    ;
               "MGR",                      ;
               "SUPER",                    ;
               "lastlog"                   ;
       COLSIZES 90,60,60,60,60,100         ;
       HEADERS "Userid",                   ;
               "Read",                     ;
               "Write",                    ;
               "ProjMgr",                  ;
               "Super",                    ;
               "Last Login"                ;
       AUTOSORT AUTOCOLS LINES CELL

       oUSER:oClient := oBrow
       oBrow:bLDblClick := { |nRow,nCol | _Userview( "V", oRsUser ) }

       oBrow:CreateFromCode()    

ACTIVATE WINDOW oUser           ;
    ON INIT( oBrow:SetFocus(), .F. );
    VALID ( IIF( !lOK, UserClose(.T., oRsUser), .F. ))

RETURN( NIL )
 


Image
User avatar
Rick Lipkin
 
Posts: 2656
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: xbrowse value of cell is nil

Postby James Bott » Tue Sep 21, 2010 11:14 pm

Rick,

I don't know if this will work with xBrowse and/or a recordset, but I have just used an if() function instead of a fieldname with TWBrowse. Something like:

if(lastlog=nil, "00/00/0000", dtoc( lastlog ) )

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: xbrowse value of cell is nil

Postby nageswaragunupudi » Wed Sep 22, 2010 1:49 am

By default, XBrowse constructs these codeblocks
Code: Select all  Expand view

oCol:bEditValue := { || oBrw:oRs:Fields( "lastlog" ):Value }
oCol:bStrData    := { || cValToStr( oCol:Value, oCol:cEditPicture ) }
 

Note: The real codeblock constructed by XBrowse is more complex than shown above, because it includes check for empty recordsets also. But that is not relevant now, if we know that this present recordset is never empty


We can override these codeblocks in our program:
Before oBrw:CreateFromCode(), insert:
Code: Select all  Expand view

oCol:bEditValue  := { || IfNil( oRsUser:Fields( "lastlog" ):Value, CToD( '' ) ) }
 

In this case Null Dates are shown as blank dates " / / ".

IfNil( a, b ) is FWH function similar to IFNULL, ISNULL, NVL in various SQL syntax. This is a replacement for If( a == nil, b, a ) but more useful. IfNil(...) can have more than 2 arguments. IfNil( a,b,c,d,e....) returns the first non-nil argument like COALESCE(). I am not sure if IfNil(..) function is available in your version. If not, you may use If( a == nil, b, a ).


If we want to show "00/00/000" instead of " / / " instead of overriding bEditValue, we can override bStrData:
Insert this line instead of the above:
Code: Select all  Expand view

oCol:bStrData  := { || If( oCol:Value == nil, "00/00/0000", cValToStr( oCol:Value, oCol:cEditPicture ) ) }
 


It goes without saying that before this line you should assign the value to oCol as oCol := oBrw:aCols[ 6 ]
Regards

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

Re: xbrowse value of cell is nil

Postby Rick Lipkin » Wed Sep 22, 2010 3:26 pm

Rao

I am using an older version of FWH 910 and the ifnil() function does not exist .. I got the remarked out code to work but your other suggestion comes back with undefined oCol ..

Code: Select all  Expand view

 oCol := oBrow:aCols[ 6 ]
      * oCol:bEditValue  := {|| If( oRsUser:Fields("lastlog"):Value == nil, ctod(""), oRsUser:Fields("lastlog"):Value) }  // this works
       oCol:bStrData  := { || If( oCol:Value == nil, "00/00/0000", cValToStr( oCol:Value, oCol:cEditPicture ) ) }

       oBrow:CreateFromCode()

 



Code: Select all  Expand view

Application
===========
   Path and name: C:\FOX\DHEC\PMOSQL\pmow32.Exe (32 bits)
   Size: 2,492,928 bytes
   Time from start: 0 hours 0 mins 6 secs
   Error occurred at: 09/22/2010, 11:21:30
   Error description: Error BASE/1003  Variable does not exist: OCOL
   Args:

Stack Calls
===========
   Called from: USERBROW.PRG => (b)_USERBROW(80)
   Called from: xbrowse.prg => TXBRWCOLUMN:PAINTDATA(8407)
   Called from: xbrowse.prg => TXBROWSE:PAINT(1333)
   Called from: xbrowse.prg => TXBROWSE:DISPLAY(990)
   Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT(1439)
   Called from: xbrowse.prg => TXBROWSE:HANDLEEVENT(10158)
   Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
   Called from:  => DIALOGBOXINDIRECT(0)
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE(273)
   Called from: .\source\function\ERRSYSW.PRG => ERRORDIALOG(343)
   Called from: .\source\function\ERRSYSW.PRG => (b)ERRORSYS(27)
   Called from: USERBROW.PRG => (b)_USERBROW(80)
   Called from: xbrowse.prg => TXBRWCOLUMN:PAINTDATA(8407)
   Called from: xbrowse.prg => TXBROWSE:PAINT(1333)
   Called from: xbrowse.prg => TXBROWSE:DISPLAY(990)
   Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT(1439)
   Called from: xbrowse.prg => TXBROWSE:HANDLEEVENT(10158)
   Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
   Called from:  => DIALOGBOXINDIRECT(0)
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE(273)
   Called from: .\source\function\ERRSYSW.PRG => ERRORDIALOG(343)
   Called from: .\source\function\ERRSYSW.PRG => (b)ERRORSYS(27)
   Called from: USERBROW.PRG => (b)_USERBROW(80)
   Called from: xbrowse.prg => TXBRWCOLUMN:PAINTDATA(8407)
   Called from: xbrowse.prg => TXBROWSE:PAINT(1333)
   Called from: xbrowse.prg => TXBROWSE:DISPLAY(990)
   Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT(1439)
   Called from: xbrowse.prg => TXBROWSE:HANDLEEVENT(10158)
   Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
   Called from:  => WINRUN(0)
   Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE(966)
   Called from: MAIN.PRG => MAIN(410)
 
User avatar
Rick Lipkin
 
Posts: 2656
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: xbrowse value of cell is nil

Postby nageswaragunupudi » Thu Sep 23, 2010 1:55 am

Code: Select all  Expand view
oCol:bStrData := { |x| x := oRsUser:Fields("lastlog"):Value, If( Empty(x), '00/00/0000',DToC(x) ) }
Regards

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

Re: xbrowse value of cell is nil

Postby Rick Lipkin » Thu Sep 23, 2010 5:41 pm

Rao

Thank you .. got it to work with your last suggestion!!

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2656
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 120 guests