Results 1 to 20 of 20

Thread: [2008] MonthCalendar help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    100

    [2008] MonthCalendar help

    How can you add events to a date with MonthCalendar?

  2. #2
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] MonthCalendar help

    I am not sure but i dont think you can actually add an event to a date with the MonthCalender. I think you will have to work with associations maybe using a List(Of ).

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2008] MonthCalendar help

    Hello there,

    Am I right in saying that what you are trying to achieve is to indicate on the calendar control which dates have an event on that day? i.e. similar to the calendar in Outlook where the dates that you have something on, they are marked in bold?

    If this is the case, then you might want to look into adding dates to the MonthCalendar AnnuallyBoldedDates, BoldedDates and MonthlyBoldedDates properties.

    These allow to add dates to the calendar that will make them appear bold, for instance:

    Code:
    monthCalendar1.MonthlyBoldedDates = new System.DateTime[] {
                    new System.DateTime(2009, 9, 26, 0, 0, 0, 0),
                    new System.DateTime(2009, 9, 30, 0, 0, 0, 0)};
    You could then use the DateChanged Event and if the selected date is one of the dates that have an event associated with it, bring up details of that event.

    Hope that helps!!!

    Gary

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    100

    Re: [2008] MonthCalendar help

    How could I have the user type in the event and then have it save the data in a text file and do it that way?

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2008] MonthCalendar help

    Hey,

    What you would need to do would be something like the following (this is a very rough approximation of one way to achieve this):

    1. Have the user select the date in the calendar
    2. Have the user enter the information regarding the event
    3. Save that information to a text file

    Then when you want to display the data

    1. Load all the information from the text file into memory
    2. Loop through all the events and find the dates and add these to the MonthCalendar as shown above
    3. When the user selects a date, display the information about that event.

    Depending on exactly what you are trying to do, a text file might not be the best approach. You might want to think about a database, or an xml file.

    If you provide some more details about what exactly you are trying to achieve, then I am sure someone here will be able to make some suggestions.

    Gary

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    100

    Re: [2008] MonthCalendar help

    hey,

    Could you please explain how I would save the data to a text file because I'm a newbie and don't know how.

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2008] MonthCalendar help

    Hey,

    Again, there are various ways to do this, and it depends on what you are trying to do, but as a rough guide, this is what you would need to do:

    1. Create a FileStream object and either create a new file, or open an existing one.
    2. Create a StreamWriter to wrap around the FileStream
    3. Use the methods of the StreamWriter to write the information to the file.
    4. Once you are done, close the StreamWriter, and then close the FileStream.

    Code:
    Dim theFile As FileStream = File.Create("C:\somefile.txt")
    Dim writer As StreamWriter = New StreamWriter(theFile)
    writer.WriteLine("Hello")
    writer.Close()
    theFile.Close()
    It is possible to bypass the need for a FileStream object by simply calling the CreateText method on the File object, which returns a StreamWriter.

    Code:
    Dim writer As StreamWriter = File.CreateText("c:\somefile.txt")
    writer.WriteLine("Hello")
    writer.Close()
    Or you can write directly to a file using the WriteAllText method.

    Code:
    File.WriteAllText("c:\somefile.txt", "Hello")
    Hope that helps!!

    Gary

  8. #8
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] MonthCalendar help

    You may find the following usefull when you want to save to a specific file path on the users computer:

    vb Code:
    1. 'Here:
    2.         'Application Start Up Path
    3.         Dim AppStartUp As String = Application.StartupPath
    4.         'Desktop
    5.         Dim Desktop As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    6.         'MyDocuments
    7.         Dim MyDocuments As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
    8.         'Application Data
    9.         Dim AppData As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    100

    Re: [2008] MonthCalendar help

    Sorry that I don't understand this, but I keep getting errors with the FileStream and StreamWriter. Can you help me with this?

  10. #10
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] MonthCalendar help

    Can we see your code?

    Otherwise just use IO.File.WriteAllText().

  11. #11
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2008] MonthCalendar help

    Hey,

    It might help if you tell me what errors you are getting?

    In order for the above to work you need to include:

    Code:
    Imports System.IO
    Gary

  12. #12
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] MonthCalendar help

    Quote Originally Posted by gep13
    Hey,

    It might help if you tell me what errors you are getting?

    In order for the above to work you need to include:

    Code:
    Imports System.IO
    Gary
    Or you can just write the full code.. namespace included.

    IO.

  13. #13
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2008] MonthCalendar help

    Quote Originally Posted by noahssite
    Or you can just write the full code.. namespace included.

    IO.
    Granted. However, if he has copied and pasted the above code, it will not work unless the Import statement is used, which would be a lot easier than appending System.IO to each object.

    Gary

  14. #14
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] MonthCalendar help

    Quote Originally Posted by gep13
    Granted. However, if he has copied and pasted the above code, it will not work unless the Import statement is used, which would be a lot easier than appending System.IO to each object.

    Gary
    Well yes.

    Also note that system is by default imported. So you would only need to append IO to each object not system.io

  15. #15
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2008] MonthCalendar help

    Again, granted. All I was trying to say was, if the above code has been copied and pasted, an Imports statement that has System.IO will be needed in order for it to work.

    Gary

  16. #16
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2008] MonthCalendar help

    red_bull_NRG,

    I have edited the code in Post #7 above, I noticed that there was an error.

    Sorry, I was in C# land there for a while. If you re-copy the code then it should now work.

    Sorry about that!!

    Gary

  17. #17
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] MonthCalendar help

    Oh ya sorry i was jumping to conclusions..

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    100

    Re: [2008] MonthCalendar help

    How can I set it so that it saves the text file in the same directory that the program is in without knowing where the directory is located?

  19. #19
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2008] MonthCalendar help

    Hey,

    In the example that I posted, replace the path to the string that I gave, i.e. C:\blah, and give it just a filename instead.

    This will then default to storing the file in the same directory as the application is currently running from.

    Gary

  20. #20
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] MonthCalendar help

    Quote Originally Posted by red_bull_NRG
    How can I set it so that it saves the text file in the same directory that the program is in without knowing where the directory is located?
    As said in post 8 (Click Here)

    To retrieve the Application StartUp path (application folder..):

    vb Code:
    1. Dim AppLocation as String = Application.StartUpPath

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width