-
Re: Mission on Outlook Calendar
Its got to be the time format. I cut off the seconds and it works fine.
([Start] >= '6/14/2007 12:00 AM') AND ([Start] < '6/15/2007 12:00 AM')
Code:
Imports Outlook = Microsoft.Office.Interop.Outlook
Public Class Form1
Private moApp As Outlook.Application
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
moApp = DirectCast(CreateObject("Outlook.Application"), Outlook.Application)
Dim MyCalendar As Outlook.MAPIFolder
Dim MyItems As Outlook.Items
Dim sToday As String
sToday = "([Start] >= '" & DateTime.Today.ToShortDateString() & " 12:00 AM')"
sToday = sToday & " AND ([Start] < '" & DateTime.Today.AddDays(1).ToShortDateString() & " 12:00 AM')"
MyCalendar = moApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
Console.WriteLine(sToday)
MyItems = MyCalendar.Items.Restrict(sToday)
TextBox1.Text = MyItems.Count.ToString & " Items for Today" '?
End Sub
End Class
-
Re: Mission on Outlook Calendar
Yipee.... it work out fine for me too...Thanks...
Didn't know it's the "seconds" who created error...
Now i left with 23 checkbox to loop.
Erm...Sry to ask this silly qns...how do i loop them?
I only learn the basic of Do & For loop which appiles to numbers..
Don't have any idea of looping checkbox which is on time-based of checkbox.
Oh... I created a button which is meant for "refresh".
That is because the user will require to get their new info with the refresh button instead of closing and opening again.
Is it possible to refresh the whole thing with the refresh button?
-
Re: Mission on Outlook Calendar
Yes. What you want to do then is create a procedure for you to call from either the Form_Load and the refresh button click events so you dont have to write it twice.
Outlook should be created if its not already running and remain open as long as you have your program open. Also, if Outlook was already open when you started your app you will want to leave it running when you app closes. ;)
To set your checkboxes you will want to put the code in your "refresh" procedure too.
Just loop through the items and set each checkbox accordingly.
Code:
Dim i As Integer
For i = 1 to 23
'Parse the time out of the Start property and eval if for each checkbox.
'MyItems.Items(x). Start
'Select Case start time hour
'Case 12
Checkbox0.Checked = True
'Case 1
Checkbox1.Checked = True
'Case 2
'...
'End Select
Next
-
Re: Mission on Outlook Calendar
As for your....
'Parse the time out of the Start property and eval if for each checkbox.
'MyItems.Items(x). Start
'Select Case start time hour
I'm not really sure what it meant..
I did as what u say and have all the checkbox0.checked = true till checkbox23.checked = true
and i got all checkbox checked ...
Maybe it's because i didn't understand your comment on that which result all checked.Sorry...
About the Refresh button, i could like to have it click and refreshed/update everything but i do not know how...
Any idea...?
-
Re: Mission on Outlook Calendar
Its was psuedocode as that way you can see the logic needed so you could write your code to go in there. ;)
-
Re: Mission on Outlook Calendar
Oh...ok...
About the refresh button, i will just copy all the code required and paste to the code for the button so when i click it will overwrite the data again, is it possible?
About the looping of the checkbox, i still do not know how to loop it correctly.
Checkbox1 = 00 : 00 till... CheckBox24 = 23 : 00
i have to link it to "today" appointment and check which timing to match with which checkbox which is confusing to me...
So i decided to create a ListBox to display the free time slot available...
The end time of the 1st appointment = start time of the free time slot ,while
The start time of the 2nd appointment = end time of the free time slot.
But i will encounter a problem which is that i will miss out all the free time slot before "start time of the very 1st appointment"... and also after "end time of the last appointment"
How do i make the listbox to display the (end time for 1st appointment while the next line is the start time of 2nd appointment)= free timing in-between.
It think it lies with the sequences of the appointment which i can't figure how to handle.
is there any way to solve it?
-
Re: Mission on Outlook Calendar
I dont see why you are switching the control/code as what I gave you in #43 is almost all the code you need. You only need to parse the time from the appointment item to determine if you need to check that hour or not.
I will help you get there but its better if you try to write the code yourself first so you can learn more. ;)
-
Re: Mission on Outlook Calendar
Hmm.... i guess it's better to display the code out...
here's the code..
vb Code:
Imports Outlook = Microsoft.Office.Interop.Outlook
Public Class Form1
Private moApp As Outlook.Application
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
moApp = DirectCast(CreateObject("Outlook.Application"), Outlook.Application)
Dim MyCalendar As Outlook.MAPIFolder
Dim MyItems As Outlook.Items
Dim sToday As String
Dim dateAndTimeDate As Date
dateAndTimeDate = Now
Dim todaysDate As Date = Today
TextBox2.Text = Today
sToday = "([Start] >= '" & DateTime.Today.ToShortDateString() & " 00:00AM')"
sToday = sToday & " AND ([Start] < '" & DateTime.Today.AddDays(1).ToShortDateString() & " 00:00AM')"
MyCalendar = moApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
Console.WriteLine(sToday)
MyItems = MyCalendar.Items.Restrict(sToday)
TextBox1.Text = MyItems.Count.ToString & " Items for Today" '?
Dim i As Integer
For i = 1 To MyItems.Count
ListBox1.Items.Add("Start Time:" & MyItems.Item(i).start.ToString())
ListBox1.Items.Add("End Time:" & MyItems.Item(i).End.ToString())
Next
End Sub
Right now there's no more checkbox as i deleted it, instead i create Listbox to display out the timing straight.
Although it can display out the appointment start time and end time but the sequence is not there as in the earliest time is not display out 1st.
Eg. 1st appointment i implent is at 2pm, 2nd appointment i implemt is at 10am.
Message display out (1st row = start time : 2pm)
(2nd row = end time : 4pm)
(3rd row = start time : 10am)
(4th row = end time : 11am)
what i need is the earliest appointment to be display out first.
Can that be done? any solution?
-
Re: Mission on Outlook Calendar
But if i use checkbox , which display 1 hour apart. Problem encounter is that the outlook appointment can start or end 30mins.
Erm.. as in start time 4 30pm to 6 30pm.Then the checkbox(1 hour) will not be accurate, which is why i have no choice but to change it to listbox and display out the exact time.
-
Re: Mission on Outlook Calendar
Ok good point. You could also use a CheckedListbox control too. :)
-
Re: Mission on Outlook Calendar
Erm...i want to try doing it with listbox first before trying out on checklistbox, because i'm new to checklistbox control, probably need some time to explore it.
So right now i use listbox and it work out fine that it display the free time slot as i used the timing of the appointment to display.
It's about the same as #48,but i face some problems
The sequence is not there as in the earliest time is not display out 1st.
Eg. 1st appointment i input is at 2pm, 2nd appointment i input is at 10am.
Message display out (1st row = start time : 2pm)
(2nd row = end time : 4pm)
(3rd row = start time : 10am)
(4th row = end time : 11am)
what i need is the earliest appointment to be display out first.
which will become...
Message display out (1st row = start time : 10am)
(2nd row = end time : 11am)
(3rd row = start time : 2pm)
(4th row = end time : 4pm)
Can that be done? any solution?
-
Re: Mission on Outlook Calendar
I wouldnt use separate listitems to display a start and stop time. Just use a single one with start/stop time in it.
To order a items collection, either restricted or not, just use the .Sort method.
Code:
MyItems.Sort "[Start]"
-
Re: Mission on Outlook Calendar
Wow....it works!!You're the Yoda!!!
But then i encounter another problem which is that if i have 2 appointment which is like
Start time = 2pm
End time = 3pm
Start time = 3pm
End time = 4pm
I try using if else to remove the 1st appointment end time and 2nd appointment start time so that it will become
Start time = 2pm
End time = 4pm
But it gives me error, saying that "Array index out of bounds."
vb Code:
If (MyItems.Item(i).start.ToString() = MyItems.Item(i).End.ToString()) Then End if
Any ideas?
-
Re: Mission on Outlook Calendar
When you remove an item from a collection the index position becomes invalid. Remove and then either reinitialize the loop or just simply loop backwards as the lower items wont change when you remove the higher item.
-
Re: Mission on Outlook Calendar
Oh...ok..i figure it out how to loop and i manage to make those appointment with high importance checked too... but then problems lies that the appointment end time is checked but start time is not.
The checklistbox i used display both the start time and end time in order as in first line is ("checkbox" "Start time :") while the next line goes ("checkbox" "End time :")
here's the code...
vb Code:
For i = 1 To MyItems.Count
If MyItems.Item(i).importance = Outlook.OlImportance.olImportanceHigh Then
CheckedListBox1.SetItemCheckState(i, CheckState.Checked)
End If
Next
Is there anything wrong with the code ? any idea?
-
Re: Mission on Outlook Calendar
That doesnt l0ook like the code for the start/end time. ;)MyItems.Item(i).End.ToString())
-
Re: Mission on Outlook Calendar
But how do i checked a string?
I got an error saying SetItemCheckState is not a member of string...
Any solution?
-
Re: Mission on Outlook Calendar
Where is the string part coming into this?
Try using
CheckedListBox1.SetItemChecked(i, True)
-
Re: Mission on Outlook Calendar
Ya ..i did try before...
There is no error in the code in #55 and i think it is about the same as your code mention but the outcome is the same which is the checkbox of the checklistbox is been checked wrongly.
For example: i got 3 appointment.
1st appointment got importance high
2nd appointment is normal
3rd appointment got importance high
What it displayed out:
End time of 1st appointment is been checked
End time of 2nd appointment is been checked
while the rest is unchecked.
So i was wondering what is wrong.
-
Re: Mission on Outlook Calendar
The loop only checks high importance items only. ;)
-
Re: Mission on Outlook Calendar
Erm..ya i know..but...
If u see #59, the display isn't right and it isn;t check high importance items.
which is why i dun know why it becomes like this...
-
Re: Mission on Outlook Calendar
Oh I see now. Because the collection is zero based and your loop is one based so they are all off by one. :)
-
Re: Mission on Outlook Calendar
Ya but then...
i got add another line and try before but there's still error
vb Code:
For i = 1 To MyItems.Count
If MyItems.Item(i).importance = Outlook.OlImportance.olImportanceHigh Then
CheckedListBox1.SetItemChecked(i, True)
CheckedListBox1.SetItemChecked(i - 1, True)
End if
For example: i got 3 appointment.
1st appointment got importance high
2nd appointment is normal
3rd appointment got importance high
What it displayed out:
Start & End time of 1st appointment is been checked
Start & End time of 2nd appointment is been checked
Error is that it should be 3rd appointment Start & End checked and not 2nd appointment.
From what i think it's probably because of the items.sort?
Any idea?
-
Re: Mission on Outlook Calendar
Because of the i-1 index. Just leave it for the next iteration otherwise you will want to loop by twos.
-
Re: Mission on Outlook Calendar
Actually i wanted both start time and end time to be checked if there's high importance for that appointment if not then start time of the appointment with high importance checked is also fine with me but i can;t seem to get it.
Wondering why~
-
Re: Mission on Outlook Calendar
If you set the check on each iteration if it passes the inportance test then you will have what you want. If you loop by twos (Step 2) you can also get it by using the i-1 index like you previously had.
-
Re: Mission on Outlook Calendar
I was thinking that if possible looping the start & End time together then that code that i use in #55 will maybe work, guess i will try it out tomorrow. If still unable to work then maybe i will display the whole code so maybe you will know if there's something wrong with my code.
-
Re: Mission on Outlook Calendar
Just post your loop as you are currently using it.
-
Re: Mission on Outlook Calendar
Like what you say, i need to try so that i can learn more and thus i'm trying my best to figure it out and now after i loop both the start time and end time together , it finally work....phew....guess seperating both start time and end could cause alot of problems... T.T
-
Re: Mission on Outlook Calendar
Well, after i get the free available time done, i wanna try to have better improvement on appointment time this time is that i will have the appointment time with the link of binary, example...
0000 0001 is from 08: 00 ~ 10: 00
0000 0010 is from 10: 00 ~ 12: 00
0000 0100 is from 12: 00 ~ 14: 00
and so on...
if i got an appointment that is from 10: 00 to 13: 00
then it will display 0000 0110
So first thing is grouping timing of the day should be the first thing right?Grouping the timing 2hours each time starting from 08:00, but then i do not know how to start...
Any ideas?
-
Re: Mission on Outlook Calendar
So you are saying that you want to group appointments every 2 hours starting from 8am?
-
Re: Mission on Outlook Calendar
Not really appointments time, to be exact is the timing starting from 08:00 till 24: 00 because i think nobody going to have a appointment before 08: 00 that early... so i will cut short to starting time of 08: 00. Binary stuff....
0000 0001 is from 08: 00 ~ 10: 00
0000 0010 is from 10: 00 ~ 12: 00
0000 0100 is from 12: 00 ~ 14: 00
0000 1000 is from 14: 00 ~ 16: 00
0001 0000 is from 16: 00 ~ 18: 00
0010 0000 is from 18: 00 ~ 20: 00
0100 0000 is from 20: 00 ~ 22: 00
1000 0000 is from 22: 00 ~ 24: 00
and these are not appointment time.It's more like a time reference, but if a appointment is within that time period like ... from 10: 00 to 13: 00 then it will display "0000 0110" in a textbox or label. And yupz...Grouping of 2 hours is needed.
-
Re: Mission on Outlook Calendar
Since there arent too many entries possible, you can just use a select case block to evaluate the time and set the labels text property accordingly to your binary requirements.
-
Re: Mission on Outlook Calendar
My idea is that if it is possible that ...
If appointment start time => 08: 00 or appointment End time< 10: 00
Then textbox1.text = 1
Else textbox1.text = 0
and keep on using ...
If appointment start time => 10: 00 or appointment End time< 12: 00
Then textbox2.text = 2
Else textbox2.text = 0
and using the last textbox to add all the values up and convert to binary...but then i have not try before... don't even know whether if there's this kind of conditions exist...( i mean the If appointment start time => 10: 00 or appointment End time< 12: 00 in the first place)...
What do you think?
-
Re: Mission on Outlook Calendar
But of course, just do like you have already done.
If MyItems..Item(i).Start >= Date.ToString & " " & 8:00" Then
etc.
-
Re: Mission on Outlook Calendar
I tried... but it gives me error
vb Code:
if MyItems.Item(i).Start >= Date.Today.TimeOfDay.Hours 08: 00 or Myitems.Item(i).End < Date.Today.TimeOfDay.Hours 10:00 then
TextBox5.Text = 1
End If
It's the time that gives error...
Any idea?
-
Re: Mission on Outlook Calendar
Whats the error? Try placing the hour time wrapped with double quotes.
-
Re: Mission on Outlook Calendar
Hmm.. ok...
vb Code:
If MyItems.Item(i).Start >= Date.Today.TimeOfDay.Hours & "08: 00" Or MyItems.Item(i).End < Date.Today.TimeOfDay.Hours & "10: 00" Then
TextBox5.Text = 1
End If
and it gives me error saying...Conversion from string "008: 00" to type 'Date' is not valid.
-
Re: Mission on Outlook Calendar
Something liek this should work.
CType(Date.Today.TimeOfDay.Hours & "08: 00", DateTime)
-
Re: Mission on Outlook Calendar
Oh...after trying it out...
vb Code:
If MyItems.Item(i).Start >= CType(Date.Today.TimeOfDay.Hours & "08: 00", DateTime) Or CType(Date.Today.TimeOfDay.Hours & "10: 00", DateTime) Then
TextBox5.Text = 1
End If
it gives me another error...
Operator 'Or' is not defined for types 'Object' and 'Date'.