FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour browse with ado and field date
Posts: 434
Joined: Wed Jun 06, 2007 02:58 PM
browse with ado and field date
Posted: 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 (fw): Select all Collapse
@ 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 24.02 - Feb. 2024 - Embarcadero C++ 7.60 for Win32 Copyright (c) 1993-2023

FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)

Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: browse with ado and field date
Posted: Fri Apr 07, 2017 01: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 (fw): Select all Collapse
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 (fw): Select all Collapse
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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: browse with ado and field date
Posted: Fri Apr 07, 2017 03:06 PM
Rao

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

Code (fw): Select all Collapse
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
Posts: 434
Joined: Wed Jun 06, 2007 02:58 PM
Re: browse with ado and field date
Posted: Fri Apr 07, 2017 03: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 24.02 - Feb. 2024 - Embarcadero C++ 7.60 for Win32 Copyright (c) 1993-2023

FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)

Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: browse with ado and field date
Posted: Fri Apr 07, 2017 03:15 PM

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

Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: browse with ado and field date
Posted: Fri Apr 07, 2017 03: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 (fw): Select all Collapse
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
Posts: 434
Joined: Wed Jun 06, 2007 02:58 PM
Re: browse with ado and field date
Posted: Mon Apr 10, 2017 06:35 AM
hi,
I changed with:
Code (fw): Select all Collapse
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 24.02 - Feb. 2024 - Embarcadero C++ 7.60 for Win32 Copyright (c) 1993-2023

FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)

Visual Studio 2019 - Pelles C V.8.00.60 (Win64)

Continue the discussion