Click here to Skip to main content
15,895,142 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Need help with SQL query Pin
Pasan1483-Sep-09 5:04
Pasan1483-Sep-09 5:04 
GeneralRe: Need help with SQL query Pin
sazd13-Sep-09 8:39
sazd13-Sep-09 8:39 
QuestionTimer set time click Pin
Bob Beaubien2-Sep-09 21:52
Bob Beaubien2-Sep-09 21:52 
AnswerRe: Timer set time click Pin
TheComputerMan2-Sep-09 22:13
TheComputerMan2-Sep-09 22:13 
AnswerRe: Timer set time click Pin
David Skelly2-Sep-09 22:57
David Skelly2-Sep-09 22:57 
AnswerRe: Timer set time click Pin
Johan Hakkesteegt3-Sep-09 0:32
Johan Hakkesteegt3-Sep-09 0:32 
GeneralRe: Timer set time click Pin
Bob Beaubien3-Sep-09 2:49
Bob Beaubien3-Sep-09 2:49 
GeneralRe: Timer set time click Pin
Johan Hakkesteegt3-Sep-09 3:31
Johan Hakkesteegt3-Sep-09 3:31 
Hello Bob,

So take your case: you want the code to be executed once a day at a specific time (was it 5:34 pm ?).

Let's take my example code again:
Dim TheButtonWasClickedToday As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  MyMessageBox(" Executed by Button1")
End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  If TheButtonWasClickedToday = False Then
            If Now.Hour = 17 Then
                Select Case Now.Minute
                    Case 34
                        MyMessageBox(" Executed exactly on time by Timer1 at " & Now.ToShortTimeString)
                        TheButtonWasClickedToday = True
                    Case Is > 40 'a 6 minute safety catch'
                        TheButtonWasClickedToday = False
                    Case Is > 34
                        If TheButtonWasClickedToday = False Then
                            MyMessageBox(" Executed too late by Timer1 at " & Now.ToShortTimeString)
                            TheButtonWasClickedToday = True
                        End If
                End Select
            End If
        End If
End Sub

Private Sub MyMessageBox(Byval ExtraMessage As String)
  MsgBox("Jiihuu!!!" & ExtraMessage)
End Sub


For it to work you would have to set the timer's interval to 1 minute (60000 milliseconds).

The problem with the timer approach, is that you are dependent on the interval. If for any reason (for example the pc freezes) the tick event is a few seconds late, your code will not be run until the next day.

So I have added the TheButtonWasClickedToday boolean to check if the code was run. In this case I have given it 6 minutes time, but you can make that smaller or larger.

Also, I am not entirely sure if checking for the hour will work with 17, as you apparently use the am/pm system. You may have to investigate that.

As for Ashfield's answer to you, you say your app will be running 24/7, but is that just to make sure that the code will be executed on time, or because the rest of the app will be doing things the rest of the time?

My advice is free, and you may get what you paid for.

GeneralRe: Timer set time click Pin
Bob Beaubien3-Sep-09 3:40
Bob Beaubien3-Sep-09 3:40 
GeneralRe: Timer set time click [modified] Pin
Bob Beaubien3-Sep-09 15:15
Bob Beaubien3-Sep-09 15:15 
GeneralRe: Timer set time click Pin
Johan Hakkesteegt3-Sep-09 20:12
Johan Hakkesteegt3-Sep-09 20:12 
GeneralRe: Timer set time click [modified] Pin
Bob Beaubien4-Sep-09 4:32
Bob Beaubien4-Sep-09 4:32 
GeneralRe: Timer set time click Pin
Johan Hakkesteegt6-Sep-09 20:05
Johan Hakkesteegt6-Sep-09 20:05 
GeneralRe: Timer set time click Pin
TheComputerMan4-Sep-09 9:59
TheComputerMan4-Sep-09 9:59 
GeneralRe: Timer set time click Pin
Bob Beaubien5-Sep-09 2:39
Bob Beaubien5-Sep-09 2:39 
AnswerRe: Timer set time click Pin
Ashfield3-Sep-09 1:34
Ashfield3-Sep-09 1:34 
GeneralRe: Timer set time click Pin
Bob Beaubien3-Sep-09 2:50
Bob Beaubien3-Sep-09 2:50 
GeneralRe: Timer set time click Pin
Ashfield3-Sep-09 3:33
Ashfield3-Sep-09 3:33 
Questioninsert excel worksheet also apply the excel formula in vb.net Pin
newdbo2-Sep-09 21:30
newdbo2-Sep-09 21:30 
AnswerRe: insert excel worksheet also apply the excel formula in vb.net Pin
Bob Beaubien2-Sep-09 21:49
Bob Beaubien2-Sep-09 21:49 
AnswerRe: insert excel worksheet also apply the excel formula in vb.net Pin
TheComputerMan2-Sep-09 22:33
TheComputerMan2-Sep-09 22:33 
GeneralRe: insert excel worksheet also apply the excel formula in vb.net Pin
valkyriexp3-Sep-09 14:04
valkyriexp3-Sep-09 14:04 
QuestionAdding controls to Existing Panel at run time in windows application Pin
kjsl2k92-Sep-09 19:16
kjsl2k92-Sep-09 19:16 
AnswerRe: Adding controls to Existing Panel at run time in windows application Pin
Muhammad Mazhar2-Sep-09 19:48
Muhammad Mazhar2-Sep-09 19:48 
GeneralRe: Adding controls to Existing Panel at run time in windows application Pin
kjsl2k92-Sep-09 19:58
kjsl2k92-Sep-09 19:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.