Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Format datetime for date in textbox

1,311 views
Skip to first unread message

Nuno Pereira

unread,
May 6, 2003, 1:26:18 PM5/6/03
to
I am to develop an application with database SQL where I
have a field datetime, when in textbox I define
controlsource for this field appears the date and the
hour, I want only the date, in grides already I decided
the problem applying ttod(field) in controlsource, but in
the textboxes it does not leave me to place this in
controlsource, as must make so that me it appears only
the date?

Darrell

unread,
May 12, 2003, 9:37:30 PM5/12/03
to
David:

Included is a program that will allow what you are trying to accomplish.

Since you are trying to do this with a grid, and if you know ahead of time
which fields will be datetime,
you could add an extra text box to the grid column of interest. If you will
not know ahead of time, you
can subclass your grid and have it add the extra 'sub-classed' text boxes to
the columns of interest at runtime.
At bit more complex, but doable.

In the example below, change the date of the first text box (txtBox1) and
press enter or click on one of the
command buttons. The underlying table field will get updated via textbox2.

txtBox2 would normally be a hidden control, but I set it's initial visible
property to .t. and included chkShowTxtBox2
to demonstrate that it is actually getting changed.

You can verify this by openning the datasession window ahead of time also.

Hope this helps...

Darrell


oForm = CREATEOBJECT("MyForm")
oForm.SHOW()
READ EVENTS

DEFINE CLASS MyForm AS FORM && Form to show the example

DOCREATE = .T.
AUTOCENTER = .T.
HEIGHT = 126
WIDTH = 288
CAPTION = "Tricking VFP's textbox control."

ADD OBJECT txtBox1 AS TEXTBOX WITH;
TOP = 24, ;
LEFT = 24, ;
HEIGHT = 23, ;
WIDTH = 144, ;
INPUTMASK = "99/99/9999" && Set with the date format you want here

ADD OBJECT chkShowTxtBox2 AS CHECKBOX WITH;
LEFT = THIS.txtBox1.LEFT+THIS.txtBox1.WIDTH + 10, ;
TOP = 24, ;
CAPTION = "Show txtBox2", ;
VALUE = .T., ;
TABSTOP = .F.

ADD OBJECT txtBox2 AS TEXTBOX WITH;
TOP = 48, ;
LEFT = 24, ;
HEIGHT = 23, ;
WIDTH = 144, ;
CONTROLSOURCE = "test.dt", ; && See the load method of the form
ENABLED = .F., ;
DISABLEDFORECOLOR = RGB(0,0,200)

ADD OBJECT cgpMoveRecord AS cgpMoveRecord WITH;
LEFT = 60, ;
TOP = 84

PROCEDURE LOAD
CREATE CURSOR test (invoice N(6),dt T)
FOR i = 1 TO 100
dt_tmp = DATETIME() + (i*86400) && Add a day to each inserted
datetime() value

INSERT INTO test (invoice, dt) VALUES (i,dt_tmp)
NEXT
GO TOP
ENDPROC

PROCEDURE REFRESH
THIS.txtBox1.VALUE = LEFT(TTOC(THIS.txtBox2.VALUE),10)
ENDPROC

PROCEDURE DESTROY
CLEAR EVENTS
CLOSE DATA ALL
ENDPROC

PROCEDURE chkShowTxtBox2.CLICK
THISFORM.txtBox2.VISIBLE = THIS.VALUE
ENDPROC

* Here's the tricks!

PROCEDURE txtBox1.VALID
THISFORM.txtBox2.VALUE = CTOT(THIS.VALUE)
THISFORM.REFRESH
ENDPROC

ENDDEFINE


* Command group class to move the record pointer

DEFINE CLASS cgpMoveRecord AS COMMANDGROUP

AUTOSIZE = .T.
BUTTONCOUNT = 4
HEIGHT = 37
LEFT = 180
TOP = 120
WIDTH = 157
NAME = "cgpMoveRecord"

Command1.LEFT = 5
Command1.CAPTION = "|<"
Command2.LEFT = 42
Command2.CAPTION = "<"
Command3.LEFT = 79
Command3.CAPTION = ">"
Command4.LEFT = 116
Command4.CAPTION = ">|"

PROCEDURE INIT
FOR i = 1 TO 4
THIS.BUTTONS(i).TOP = 5
THIS.BUTTONS(i).HEIGHT = 27
THIS.BUTTONS(i).WIDTH = 36
NEXT
ENDPROC

PROCEDURE CLICK
DO CASE
CASE THIS.VALUE == 1
GO TOP
CASE THIS.VALUE == 2
SKIP -1
IF BOF()
GO BOTTOM
ENDIF
CASE THIS.VALUE == 3
SKIP
IF EOF()
GO TOP
ENDIF
CASE THIS.VALUE == 4
GO BOTTOM
ENDCASE

* Have to refresh the control that connects to the
* table field first
THISFORM.txtBox2.REFRESH
THISFORM.REFRESH
ENDPROC

ENDDEFINE

"Nuno Pereira" <n.pe...@desis.pt> wrote in message
news:012201c313f4$9aff33b0$a301...@phx.gbl...

0 new messages