browse with ado and field date

browse with ado and field date

Postby damianodec » Fri Apr 07, 2017 10:05 am

hi,
I have this Select:
"SELECT cData as DATAOP FROM..."
that return a field with this char value "27/01/2017"
then I have
Code: Select all  Expand view
@ 40,10 XBROWSE oBrw SIZE -10,-50 PIXEL ;
RECORDSET oRs AUTOSORT ;
COLUMNS "DATAOP", ....

in my Browse I would like to convert DATAOP field from char to Date.

thank you
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 419
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia

Re: browse with ado and field date

Postby nageswaragunupudi » Fri Apr 07, 2017 1:52 pm

I assume that the data is stored in the database in character format ( DD/MM/YYYY ) ( note: this is a very rare practice) and also assuming that the dateformat set in your program is also DD/MM/YYYY, then

Code: Select all  Expand view

oBrw:DataOp:bEditValue := { || CTOD( IfNil( oRs:Fields( "DATAOP" ):Value, "" ) ) }
 

With this you can read and display the value as date but you can not edit.

If you also want to edit and save changes in character format again
Code: Select all  Expand view

oBrw:DataOp:bEditValue := { |x| If( x == nil, CTOD( IfNil( oRs:Fields( "DATAOP" ):Value, "" ) ), oRs:Fields("DATAOP"):Value := DTOC( x ) ) }
 
Regards

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

Re: browse with ado and field date

Postby Rick Lipkin » Fri Apr 07, 2017 3:06 pm

Rao

Don't forget you need to guard against Nil if that date field is empty .. or you are at Eof

Code: Select all  Expand view

oCol:bStrData := { |x| x := if(oRsUser:eof, ,TtoDate(oRsUser:Fields("LastLog"):Value)),;
                                     If( Empty(x), ctod(""),x ) }


//--------------------------
Function TtoDate( tDate )

If empty( tDate)
   Return( ctod("00/00/00"))
Endif

If ValType( tDate ) = "D"
   Return(tDate )
Endif

Return( stod( substr( ttos( tDate ), 1, 8 ) ))

 


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

Re: browse with ado and field date

Postby damianodec » Fri Apr 07, 2017 3:11 pm

thank you Mr
but I get Erro when compile.

FiveWin for xHarbour 12.01 - Jan. 2012
dataor.prg(380) Error E0030 Syntax error: "syntax error at '}'"

this is Row 380:
oBrw:Dataop:bEditValue := { || CTOD( oRs:Fields( "DATAOP" ):Value }

I also tried in this way to understand the problem:
oBrw:Daiop:bEditValue := " "

it compile but when run I get Error:
Application
===========
Path and name: C:\MyExe.exe (32 bits)
Size: 2,179,584 bytes
Compiler version: xHarbour build 1.2.1 Intl. (SimpLex) (Rev. 9421)
FiveWin Version: FWHX 11.12
Windows version: 6.2, Build 9200

Time from start: 0 hours 0 mins 8 secs
Error occurred at: 07-04-2017, 17:05:37
Error description: Error BASE/1004 Message not found: TXBROWSE:DATAOP

Stack Calls
===========
Called from: .\source\function\HARBOUR.PRG => _CLSSETERROR( 166 )
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:DATAOP( 7728 )
Called from: dataor.prg => DATAOR11( 380 )

thank you
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 419
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia

Re: browse with ado and field date

Postby nageswaragunupudi » Fri Apr 07, 2017 3:15 pm

I just made a correction in the code.
Please copy and run again.
Regards

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

Re: browse with ado and field date

Postby nageswaragunupudi » Fri Apr 07, 2017 3:18 pm

Rick Lipkin wrote:Rao

Don't forget you need to guard against Nil if that date field is empty .. or you are at Eof

Code: Select all  Expand view

oCol:bStrData := { |x| x := if(oRsUser:eof, ,TtoDate(oRsUser:Fields("LastLog"):Value)),;
                                     If( Empty(x), ctod(""),x ) }


//--------------------------
Function TtoDate( tDate )

If empty( tDate)
   Return( ctod("00/00/00"))
Endif

If ValType( tDate ) = "D"
   Return(tDate )
Endif

Return( stod( substr( ttos( tDate ), 1, 8 ) ))

 


Rick Lipkin

Mr Rick
I modified the code for nil values.
With xbrowse we need to worry about Eof condition at all

bStrData and bOnPostEdit were deprecated many years back. I would appeal to you change please.
Regards

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

Re: browse with ado and field date

Postby damianodec » Mon Apr 10, 2017 6:35 am

hi,
I changed with:
Code: Select all  Expand view
oBrw:DataOp:bEditValue := { || CTOD( IfNil( oRs:Fields( "DATAOP" ):Value, "" ) ) }


but get this again:
Application
===========
Path and name: C:\MyEXE.exe (32 bits)
Size: 2,179,584 bytes
Compiler version: xHarbour build 1.2.1 Intl. (SimpLex) (Rev. 9421)
FiveWin Version: FWHX 11.12
Windows version: 6.2, Build 9200

Time from start: 0 hours 0 mins 14 secs
Error occurred at: 10-04-2017, 08:22:20
Error description: Error BASE/1004 Message not found: TXBROWSE:DATAOP

Stack Calls
===========
Called from: .\source\function\HARBOUR.PRG => _CLSSETERROR( 166 )
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:DATAOP( 7728 )
Called from: dataor.prg => DATAOR11( 380 )
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 419
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 106 guests