Reload data in a UICollectionView - Swift - uicollectionview

I am trying to create a simple calendar using UICollectionView. Everything seems to be working fine. I need to trade the calendar according to months i.e. when I click a button the month should be changed to previous month and the text in all the cells should change according to the previous month.
I tried using collectionview!.reloadData() but my app is crashing because of this. I even tried deleting all the cells and then reloading but it docent work either.
Here is my code:
#IBAction func prevMonth(){
day = -1
if(month == 1){month = 12
year = year-1}
else{
month = month-1}
let firstdate = "01-\(month)-\(year)"
let dcalender = NSCalendar.currentCalendar()
let formatter:NSDateFormatter = NSDateFormatter()
formatter.dateFormat = "dd-MM-yyyy"
let dateComponents = dcalender.components([.Weekday],fromDate: formatter.dateFromString(firstdate)!)
weekday = dateComponents.weekday
self.collectionView?.reloadItemsAtIndexPaths((self.collectionView?.indexPathsForVisibleItems())!)
}
My Error:
Invalid update: invalid number of items in section 1. The number of items contained in an existing section after the update (35) must be equal to the number of items contained in that section before the update (31), plus or minus the number of items inserted or deleted from that section (31 inserted, 31 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).
I am new to swift and to iOS development so maybe I am missing a very simple point. Please help me out.
UPDATE
I finally understood the reason. It is happening because when I add cells for a particular month, I add them according to the weekdays. So if the 1st day of the month is a Tuesday, I add 2 extra cells at the beginning to skip Sunday and Monday. That is why the number of cells before and after an update is conflicting.
What is another way to resolve this?

I finally resolved this question.
For anyone who encounters the same issue:
Use reloadData() and it will work perfectly fine. My app was crashing because it was running out of indexes in my days array.
Hope this helps :)

Related

Change Outlook appointment series having a starting date in the past

maybe you've experienced this, too. When I get involved into a project that is already running the project lead or scrumm master forward me appointment series like daily stand-ups or similar and the series started long before the day I receive the invitation.
Let's asume the following as example:
The series starts on January, 11th 2021 (Monday) and re-occurs every week.
I receive the invitation in my inbox on March, 16th 2021 (Tuesday).
When I look into my calender I will see this appointment in January, February etc. although I didn't participate back then because I wasn't assigned. To keep my calender in a way that it shows what really happend I have to manually remove all those occurances.
What I want to archieve is this:
The invitation enters my inbox.
Application_NewMailEx is triggered and runs a piece of VBA code that checks for a series like the following.
(...)
If TypeName(objInboxObject) = "MeetingItem" Then
Set objAppt = objInboxObject.GetAssociatedAppointment(False)
If Not objAppt Is Nothing Then
If objAppt.IsRecurring Then
Set objRecurrPatt = objAppt.GetRecurrencePattern
If Not objRecurrPatt Is Nothing Then
(...)
That's easy to handle but now the tricky part that I cannot find a solution anywhere and I really hope one of you can help me.
How I can I find out the NEXT FUTURE occurance starting from TODAY (the date I received it)? In the example this would be March, 22nd 2021. Especially if the re-occurance pattern is more complex than in the example.
Then I would replace the start date of the series with this calculated date and save the MeetingItem. If I accept it in the normal Outlook window I will have one calendar entries in the future and none in the past.
Analyzing the RecurrencePattern object you can find the date of the next occurrence. Then you can use the RecurrencePattern.GetOccurrence method which returns a specific instance of the AppointmentItem object on the specified date. The GetOccurrence method generates an error if no appointment of that series exists on the specified date.

How to see if a week past from a specific date?

I am making a VB.Net WinForm application. In which every week a setting will have to get reset and another setting(the date) will have to be updated.
For example:
The date is 7/17/18. On the 7/24/18, the setting will be reset and the date setting will be 7/24/18 so the function can go on. I know how to update and reset the setting. I just don't know how to say "a week from this date".
Thanks in advance for the help!
The easiest way would be to create an application level setting with user scope to store your last date, then you can compare the current date with the stored date to see if 7 days have past.
There are a few ways you could handle it, but to avoid culture issues, personally I have found that the easiest way is to store the date as a string in the international date format, so no matter what format the system uses for dates, the date will ALWAYS be in a recognisable format.
This method eliminates problems that could come up if the system's regional settings change:
My.Settings.DateSetting = Date.Today.ToString("yyyy-MM-dd")
To see if a week has passed from your previous date:
If Date.Today >= Cdate(My.Settings.DateSetting).AddDays(7) Then
'Do your stuff here
' ...
'Add one week to the previous date and save the setting
My.Settings.DateSetting = CDate(My.Settings.DateSetting).AddDays(7).ToString("yyyy-MM-dd")
My.Settings.Save()
End If

Sorting the data in a cell in GoogleSpreadsheets to extract just one component

I am using this ImportRange formula to call information from one column of a spreadsheet into a different google spreadsheet.
=FILTER(ImportRange("key","onfleet_export!U:U"), ImportRange("key","onfleet_export!AE:AE")>=DATEVALUE(C2), ImportRange("key","onfleet_export!AE:AE")<=DATEVALUE(C3+2))
That formula works fine. My problem arises when I look at the data in the cell. I want to find a formula that will pull only one part of the old cell's contents into the new spreadsheet's cell.
Each cell in my old spreadsheet looks something like this:
url / 12PM - 4PM / Condition: 85 / elevator / Product Notes:
The only part that I want to have in my new spreadsheet is the 12PM - 4PM part. The times can be 7AM-12PM, 12PM-4PM, and 4PM-8PM- but there are a few exceptions to this rule.
I would really appreciate any suggestions that you can provide. I was thinking of using the QUERY formula, but can't seem to find any guides on how to implement this.
Thank you!
var dataAsList = cellData.split('/');
var desiredData = dataAsList[1];
If your date is always in the same place, this is easy, (even if it isn't the prettiest).

VBA Excel 2003/2007: Declaring, Filling, and Passing a Jagged Array

I have thoroughly researched this topic and have yet to find code that works to accomplish what I need to do. In a nutshell, I'm creating a Production Tracking program and the feature of it on which I'm working now involves accurately tracking vacation days for 5 employees. A userform containing 5 listboxes, one for each employee, is used to select which days each employee took off for the week. The problem comes when I try to create unique dynamic arrays containing each employees' days off. I figured out how to create an array that captures this information but it's one array that gets reassigned each time the loop iterates. I need to have a unique array for each employee containing his days off to be used later in the code to adjust weekly scoring depending on his available days of work. Below is my code in the userform for to create a create the jagged array:
Public Name_Jagged() As Variant
For Each Name In Name_Array
Set Unique_Listbox = Controls(Name & "_Vacation")
For UnSelected = 0 To Unique_Listbox.ListCount - 1
If Unique_Listbox.Selected(UnSelected) = False Then
ReDim Preserve Name_Jagged(0 To UBound(Name_Jagged) + 1)
Name_Array(Name) = Name_Jagged()
Name_Jagged(UBound(Name_Jagged)) = Unique_Listbox.List(UnSelected)
End If
For UnSelected_Array_Pos = LBound(Name_Jagged) To UBound(Name_Jagged)
MsgBox Name & "_" & Name_Jagged(UnSelected_Array_Pos)
Next UnSelected_Array_Pos
Next UnSelected
Next Name
The compiler will not allow me to use Public Name_Jagged()() As Variant either despite most other forums saying this is how it's supposed to be written. The only other post I found online regarding this jagged array declaration issue was not answered.
I would really appreciate your help. I've been able to figure out everything so far from previous threads but this has eluded me. If there is a better option than jagged arrays to accomplish this, I'm all ears. I read in some forums about using Lists but I am not at all familiar with them or how to use them at this point. Thanks in advance for the help.
Just a thought but why have 5 static listboxes for each employee?
Why not just have 1 list box which contains the names of the employees and 1 list box which contains the days of the week. You highlight the employee you want and than select the days which they've taken off. Hit a submit button which would load the employees name into an array with the days selected? The array could be structured like this
NAME | MONDAY | TUESDAY | WEDNESDAY | THURSDAY | FRIDAY | SATURDAY | SUNDAY
JIM..... OFF............ OFF
ERIC.......................OFF.............OFF
And so on. This way if you need to add people in the future you just add them to the list box. You would than have one simple array to deal with?
Also you said "to be used later in the code to adjust weekly scoring depending on his available days of work"
A suggestion; You may want to consider logging it to a simple mysql/mssql database which gives you far more flexibility and control for the future.

Delete files that are not updated

Does anyone know if it is possible to delete a document that is not updated by a certain time. I am trying to make a blank inspection sheet repopulate every night at 12:01 AM and if no one enters in inspection information for that day, the form for that day be deleted so I don't have a surplus of blank inspection forms saved.
Yes it is possible. here is the base code. You need to change the if statement to reflect the correct time period.
Dim oFileObj
Set oFileObj = Wscript.CreateObject("WScript.FileSystemObject")
oFileObj.GetFile("File.Name")
if oFileObj.DateLastModified < NOW then
oFileObj.DeleteFile("File.Name")
end if
Set oFileObj = Nothing