Results 1 to 2 of 2

Thread: [2005] Program Runs at Specific Time

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    [2005] Program Runs at Specific Time

    Hi, right now I have a program that copies an Access file to a mapped drive. I have it run on the load event and then fire a timer every 60 minutes. I'm using a DTS package to convert my access file to a SQL database and it's a large file so I need my program to run after the DTS package runs. I'm not sure how to look at the system time and determine whether or not the program should run. I want the file to copy 10 after the hour every hour. I know this is very simple but I've never dealt with anything like this. Help?

  2. #2
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2005] Program Runs at Specific Time

    The system time is available as a System.DateTime object "Date.Now". This has properties such as Hour, Minute, Day, Month etc.

    You could run a sub at a specific time by doing something like the code below. I didn't test this but it should give you the general idea. You could use a timer synchronized to 10 past the hour too.

    Code:
            Dim DateString As String = Date.Now.ToString("dd/MM/yyyy hh:10")
            Dim NextTime As Date
    
            'This could be set/unset by a button click 
            Dim ProgramIsEnabled As Boolean = True 
    
            If Date.TryParseExact(DateString, "dd/MM/yyyy hh:mm", Nothing, _
            Globalization.DateTimeStyles.None, NextTime) Then
                While ProgramIsEnabled
                    While Date.Now < NextTime
                        'Sleep for 1 minute
                        System.Threading.Thread.Sleep(60000)
                    End While
                    'Do stuff
                    NextTime = NextTime.AddHours(1)
                End While
            End If

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