Subject |
Re: time calculations |
From |
Mervyn Bick <invalid@invalid.invalid> |
Date |
Sat, 14 Nov 2020 11:52:40 +0200 |
Newsgroups |
dbase.getting-started |
Attachment(s) |
duration.wfm |
On 2020/11/14 07:50, Moses Hanna wrote:
> I am quoting down under a form image
> I am trying to calculate duration time in minutes for the last two days
> i am trying but unsuccessful
> I practiced programing long time ago
> now I have forgotten many many thing
> now I need help
> how to fill ef3 of the form with number of duration time in minutes
> any help please
It is not a good idea to copy files from the dUFLP into your working
directory unless you are going to make changes to the original code.
And if you do this you should change the name of the file to avoid
possible confusion later. Rather use a source alias in your code to
refer to the original file in the dUFLP. When you include the file from
the dUFLP in the application project file you will need to use the
actual path rather than the source alias.
If you are using visible controls from a custom class the form designer
is happy with the 'set procedure to...' command at the top of the class
definition. Where the procedure file is used to give access only to
functions the form designer will discard that line when the form is
saved. To gain access to functions place the 'set procedure to...'
command in the form's onOpen even handler.
Using a codeblock as an event handler has it's uses but, as all the code
for a codeblock must be in one line, it tends to become "messy" for more
complex code. I've removed the onClick event handlers for your
pushbuttons and used functions instead.
dBASE is fussy about object names. You used form.ef1 and form.ef2 in
your codeblocks but you had changed the actual names of the entryfields
to form.time1ef and form.time2ef in the constructor code. dBASE was not
happy. :-)
Use the dBASE function time(), rather than date(), if you want the
duration of a visit measured in minutes. I've assumed that you don't
need (or want) the seconds displayed.
I've reworked your form and named it duration.wfm. A copy is attached.
As it stands the form shows the in and out times as hh:mm. The duration
is calculated by assuming the time in is hh:mm:00 and the out time is
hh:mm:59.
If this is not what you want you will need to be specific. The example
was created using dBASE 2019. If you are using a different version
please mention this in future posts.
Mervyn.
| ** END HEADER -- do not remove this line
//
// Generated on 2020-11-14
//
parameter bModal
local f
f = new durationForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif
class durationForm of FORM
with (this)
onOpen = class::FORM_ONOPEN
height = 9.5455
left = 124.4286
top = 4.4091
width = 48.5714
text = ""
endwith
this.PB1 = new PUSHBUTTON(this)
with (this.PB1)
onClick = class::PB1_ONCLICK
height = 1.0909
left = 5.0
top = 2.2727
width = 15.2857
text = "Client In"
endwith
this.TIME1EF = new ENTRYFIELD(this)
with (this.TIME1EF)
height = 1.0
left = 22.0
top = 2.1818
width = 12.1429
function = "I"
value = ""
endwith
this.PB2 = new PUSHBUTTON(this)
with (this.PB2)
onClick = class::PB2_ONCLICK
height = 1.0909
left = 5.0
top = 4.5455
width = 15.2857
text = "Client Out"
endwith
this.TIME2EF = new ENTRYFIELD(this)
with (this.TIME2EF)
height = 1.0
left = 22.0
top = 4.5455
width = 12.1429
function = "I"
value = ""
endwith
this.TEXT1 = new TEXT(this)
with (this.TEXT1)
height = 1.0
left = 5.0
top = 6.3636
width = 15.0
text = "Duration In (Mins)"
endwith
this.DURATIONEF = new ENTRYFIELD(this)
with (this.DURATIONEF)
height = 1.0909
left = 22.0
top = 6.0
width = 12.0
value = ""
endwith
function PB1_onClick()
form.time1ef.value = substr(time(),1,5)
form.time2ef.value = ''
form.durationef.value = ''
return
function PB2_onClick()
local duration,duration_mins
form.time2ef.value = substr(time(),1,5) //this time() is dBASE function i.e not from time.cc
duration = form.time.difftime(form.time1ef.value,form.time2ef.value)
duration_mins = int(form.time.time2sec(duration)/60)
form.durationef.value = iif(duration_mins = 0,1,duration_mins) //never display 0. Minimum time is 1 minute
return
function form_onOpen()
set procedure to:duflp:time.cc
form.time = new time() // this time() is creating an instance of the class in time.cc
return
endclass
|
|