AppleScript : incrementing and reseting after a day - count

I have an AppleScript saved as an app, I run it a few time a days, and I want to added a counter.
property currentCount : 0
increment()
on increment()
set currentCount to currentCount + 1
display dialog "Count is now " & currentCount & "."
end increment
This is adding 1 each time the script is running even if I close and open it again, but how can I reset it ?
I mean the goal is to count the number of "case" every day and then start over the day after.
How can I just reset automatically the next day ?
Cheers

Try this, it uses an additional property for the current date.
property today : missing value
property currentCount : 0
increment()
on increment()
set currentDate to short date string of (current date)
if currentDate is not today then
set today to currentDate
set currentCount to 0
end if
set currentCount to currentCount + 1
display dialog "Count is now " & currentCount & "."
end increment

Related

Comparing date/time values in microsoft access 2010

I am having some trouble comparing date/time values in Microsoft Access.
I am currently using the query below to get all the absence records for the day. I have no issues when it is a plain date value but records with time included cannot be retrieved with the query.
SELECT * FROM table_name
WHERE [Start Date/Time] <= Date() AND [End Date/Time] >= Date()
I have a table used to store absence records of the following form.
Name: Text
Start Date/Time: Date/Time
End Date/Time: Date/Time
You can for example use:
SELECT * FROM table_name
WHERE Fix([Start Date/Time]) <= Date() AND Fix([End Date/Time]) >= Date()
to remove the time part, or:
SELECT * FROM table_name
WHERE DateDiff("d", [Start Date/Time], Date()) >= 0 AND DateDiff("d", [End Date/Time], Date()) <= 0
to ignore the time part.

How to compare Starting time and End time of a event with existing events of same time on same day?

I am using MS SQL server 2008. Here I need to compare the newly entered start time and End time of an event with the existing event timings. In the Database I need to check the new Starting time and End time values and the time Period should not match with the existing/ already booked event timings.
I need to check this condition in the Database stored procedure, if the condition is satisfied then only accept the event. Best example is Conference hall booking.
SELECT #count = COUNT (EventID) FROM TblEvent WHERE (('#STARTTIME' BETWEEN StartTime AND EndTime) or ('#ENDTIME' BETWEEN StartTime AND EndTime));
IF #count = 0
Begin
Select #count = COUNT (EventID) FROM TblEvent WHERE (('#STARTTIME' < StartTime and '#ENDTIME' > EndTime));
END
IF #count > 0
BEGIN
SELECT 'Event is Already Exists at that point of time please select another Time ' AS 'MESSAGE';
END
Else
BEGIN
//ADD QUERY TO SAVE THE THE EVENT IN DB//
SELECT 'Event is Added' AS 'MESSAGE';
END
NOTE:
#STARTTIME = USER ENTERED START TIME,
#ENDTIME =USER ENTERED END TIME
You can use 24 hour format to solve this in your logic. you have to save existing event timings in Database. whenever new event timings entered, you need to compare with existing both start & end timings with previous ones.
For Example:
Event1: x1 to y1
Event2; x2 to y2
if(x2==x1 && y2==y1)
if(x2>x1 &&x2<y1) andif(y2<y1)
...so on based on your requirement.
Answer is (StartA <= EndB) and (EndA >= StartB). Please, read these: Determine Whether Two Date Ranges Overlap
Hey Sanjeev try the following code..!
Select * From your Event
WHERE ('A' BETWEEN StartTime AND EndTime) or ('B' BETWEEN StartTime AND EndTime)
Note:
Here A and B are your Start time and End Time,
and Italics are your database values.
If I had understood correctly, this should solve the problem.
Let us take A and B are your start time. X and Y are previously in Database.
Then (A,B) does not over lap (X,Y) when X > B or Y < A this can be told as the new event must finish before the previous one or it must start after the previously available one. So query must be
...
Where NewStartTime > EndTime or NewEndTime < StartTime;

PL/SQL in oracle reports, incrementation doesn't work

In my response 2 rows is different from '.' and will therefor print out, and should increment the "myCounter".
But in both the print outs 1 as in myCounter doesn't gets incremented...
function R_G_cnFormatTrigger return boolean is
myCounter number :=0;
begin
-- Automatically Generated from Reports Builder.
if (mod(myCounter,2) = 0)
then
srw.set_foreground_fill_color('gray8');
srw.set_fill_pattern('solid');
else
srw.set_foreground_fill_color('');
srw.set_fill_pattern('transparant');
end if;
if(:CP_WAYBILL_NO <> '.')
then
myCounter:=(myCounter+1);
srw.message(123,'myCounter:'||myCounter);
return true;
else
return false;
end if;
end;
When you print myCounter it always equals 1, right? This is because you return true; at the end of if(:CP_WAYBILL_NO <> '.').
When you use return in function, it breaks the execution. myCounter is a local variable, so its value isn't remembered.
You can try creating a package with myCounter as global variable or read/write myCounter from/to temporary table.

Difference between two date/time fields - Lotus Notes

I have three editable date/time fields which the first two is (field1 and field2), style: Calendar/time control. Both of them are showing the time: hour and minutes, eg: 15:51.
The third field also (editable) which I want to show the difference between field1 and field2.
Eg: If field1 is 14:41 and field2 is 14:30, then field3 = 00:11. I've tried field1-field2 but isn't working. The form has automatic refresh fields property. Thanks!
Your third field needs to be computed, not editable.
If it HAS to be editable for some reason, and you want it to update when the other two fields are changed, do this:
Create a new field and make it computed-for-display and hidden. Give it a formula like this
#If(field1=null | field2=null; #Return(""); "");
seconds := field1-field2;
hours := #Integer(seconds/3600);
minutes := #Modulo(#Integer(seconds/60); 60);
output := #Right("00" + #Text(hours); 2) + ":" + #Right("00" + #Text(minutes); 2);
#setfield("field3"; output);
#Command([ViewRefreshFields]);
""
Phil
I wrote this code, much easier...
Fields 'StartTime' and 'EndTime':
Type Date/Time, use Calendar/Time control, set it to only display time.
Check the property "Run Exiting/OnChange events after value changes".
The Exiting event should look like this:
Sub Exiting(Source As Field)
Call UpdateDuration()
End Sub
Field 'Duration':
Editable text field, but hidden.
Field 'dspDuration':
Computed for display text field. Value is just "Duration" (no quotes).
Then add the following code to the forms Global section:
Sub UpdateDuration()
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim starttime As NotesDateTime
Dim endtime As NotesDateTime
Dim duration As Integer
Set uidoc = ws.CurrentDocument
'*** Exit if not both times are entered
If uidoc.FieldGetText("StartTime") = "" Then
Exit Sub
Elseif uidoc.FieldGetText("StartTime") = "" Then
Exit Sub
End If
'*** Calculate duration in seconds and update field
Set starttime = New NotesDateTime( uidoc.FieldGetText("StartTime") )
Set endtime = New NotesDateTime( uidoc.FieldGetText("EndTime") )
duration = endtime.TimeDifference( starttime )
Call uidoc.FieldSetText("Duration", Cstr(duration) )
Call uidoc.Refresh()
End Sub
That's it. Easy, isn't it? If you want to modify the output (duration), you can easily do that, perhaps change it into minutes by diving it by 60.
Make sure you are getting the difference between two date time fields. If you need to, you can use the #TextToTime formula to convert text to a datetime type.
Then just subtract the first date from the second date and you'll get the difference in seconds.
Then divide that by 60 to get the difference in minutes.

Loop for each day in the current month and check rows for a match

How can I write a loop to run for each day in the current month and then check to see if the Dataset has a record that matches one of those days and take an action?
For Day As Integer = 1 To DaysInTheMonth
For Each row In MyRows
If row.Date.Day = Day Then
' Yup! Found Data for this day!
' Add Data to string
Else
' No Data To Display
' Add Blank Field String
End If
Next
Next
This generates too many rows in the table I have it building. Basically, every day gets as many rows as there are that contain data.
I'm building a HTML table that gets mapped into a chart using jquery so I need a for everyday of the month.
I think what would more suit your run would be having a day counter in the loop for the rows, so that you don't actually run over all the days again for each record in the datatable.
So now if you have the record its added to the string else skipped and the dat is incremented, so going down further you should get the required datapoints. give it a try
For Each row In MyRows
If row.Date.Day = Day Then
' Yup! Found Data for this day!
' Add Data to string
Else
' No Data To Display
' Add Blank Field String
End If
Day = Day + 1;
Next
You should drop the first For loop as that's causing all rows to be selected. Instead set Day = Today. Ie
Day as Integer = date.day

Resources