A little Alarm for 6 Hours?

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 3295 Views - Last Post: 14 September 2012 - 07:28 PM Rate Topic: -----

#1 Matthieu503  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 21-August 12

A little Alarm for 6 Hours?

Posted 21 August 2012 - 11:35 AM

Hello, I am making a little program where if the web browser is navigated to a specific url, there comes a function. I am trying to make the function work again only after 6 hours. Heres what I have so far
         Dim After6Hours As String = TimeOfDay + "6"
         Dim JobTime As String = TimeOfDay
         Private Sub WebBrowser4_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser4.DocumentCompleted
        If WebBrowser4.Url.ToString = "http://NavigatedLinkHere.com" Then
            WebBrowser4.Navigate("http://WhenNavigatedNavigateHere.com")
            WebBrowser4.Hide
            Label2.Hide
            Label3.Show
        End If
        End Sub
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Label3.Text = "After6hours"
        End Sub



I was thinking of doing something like this.
Dim After6Hours As String = TimeOfDay + "6"


Also, I want it to be stored in like the settings so like
My.Settings.Time = After6Hours

Form_Load
If DayOfTime = After6Hours Then



The Above code is probably really dumb, and I'm sorry as I have just started developing visual basic

Oh In the coding, I meant to put
Dim After6Hours As String = JobTime + "6"

Not
Dim After6Hours As String = TimeOfDay + "6"


Is This A Good Question/Topic? 0
  • +

Replies To: A little Alarm for 6 Hours?

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9576
  • View blog
  • Posts: 36,274
  • Joined: 12-June 08

Re: A little Alarm for 6 Hours?

Posted 21 August 2012 - 11:40 AM

Why not just use a 'scheduled task' in the control panel to kick off the app every six hours?
Was This Post Helpful? 0
  • +
  • -

#3 Matthieu503  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 21-August 12

Re: A little Alarm for 6 Hours?

Posted 21 August 2012 - 12:09 PM

Where can I find the control panel?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9576
  • View blog
  • Posts: 36,274
  • Joined: 12-June 08

Re: A little Alarm for 6 Hours?

Posted 21 August 2012 - 12:21 PM

:blink: Really?
start -> settings -> control panel.
Was This Post Helpful? 0
  • +
  • -

#5 fatalpriapism  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 39
  • Joined: 17-August 12

Re: A little Alarm for 6 Hours?

Posted 21 August 2012 - 12:50 PM

Erm. Start menu-> control panel.

Pretty please tell me that your a diehard anti-Windows *nix junky
Was This Post Helpful? 0
  • +
  • -

#6 Matthieu503  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 21-August 12

Re: A little Alarm for 6 Hours?

Posted 21 August 2012 - 01:14 PM

Oh, that control panel, That wouldn't work with this program because it is used by a lot of people, so is there another way?
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9576
  • View blog
  • Posts: 36,274
  • Joined: 12-June 08

Re: A little Alarm for 6 Hours?

Posted 21 August 2012 - 01:15 PM

What do you mean?
Was This Post Helpful? 0
  • +
  • -

#8 ToshNeox  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 100
  • Joined: 10-December 11

Re: A little Alarm for 6 Hours?

Posted 21 August 2012 - 01:27 PM

You could get the current time, then add on 6 hours and use a timer to check when it gets to that time.

You need to define the current time and 6 hours from now:

Dim epoch = New DateTime(1970, 1, 1)
Dim curTime = DateTime.Now
Dim newTime = curTime.AddSeconds(21600000) 'Add 6 hours worth of milisecs.



Now create a timer and set the interval to 1 hour:

Dim timer As Timer
timer.Interval = 3600000 'One hour worth of milisecs.



And now handle the timer:

Private Sub MyTimerTick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyTimer.Tick
' Check if curTime = newTime and if so, do alarmy-style stuff :D/>
End Sub



Of course you could just create a timer with an interval of 6 hours, but I'm not sure how stable timers are with long times, so perhaps it may improve reliability to set the timer to something like 10 minutes interval - you might want to do some testing on that.

I hope that's what you were looking for? It might be more difficult if you were looking to track the time through PC reboots etc...

This post has been edited by ToshNeox: 21 August 2012 - 01:47 PM

Was This Post Helpful? 1
  • +
  • -

#9 Matthieu503  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 21-August 12

Re: A little Alarm for 6 Hours?

Posted 21 August 2012 - 07:30 PM

Hmm I'll try that but I will of course tweak it a bit
Was This Post Helpful? 0
  • +
  • -

#10 Matthieu503  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 21-August 12

Re: A little Alarm for 6 Hours?

Posted 21 August 2012 - 08:15 PM

So I tried it, heres what I did. It didn't redirect me to the next URL though
    Dim epoch = New DateTime(1970, 1, 1)
    Dim curTime = DateTime.Now
    Dim newTime = curTime.AddSeconds(21600000) 'Add 6 hours worth of milisecs.
    Dim newTime2 = My.Settings.Time
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer2.Interval = 3600000 'One hour worth of milisecs.
    End sub
    Private Sub WebBrowser4_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser4.DocumentCompleted
        If WebBrowser4.Url.ToString = "ArrivalURLHere" Then
            WebBrowser4.Navigate("http://AfterLinkHere")
            Timer2.Start()
            My.Settings.Time = curTime
            WebBrowser4.Hide()
            Label8.Hide()
            Label12.Show()
        End If
        Dim JobTime As String = TimeOfDay
    End Sub


    Private Sub WebBrowser3_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser3.DocumentCompleted

    End Sub

    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        Label12.Text = "Time When you can vote again" & curTime
        If curTime = newTime2 Then
            WebBrowser4.Show()
            Label8.Show()
            Label12.Hide()
        End If
    End Sub


Was This Post Helpful? 0
  • +
  • -

#11 ToshNeox  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 100
  • Joined: 10-December 11

Re: A little Alarm for 6 Hours?

Posted 22 August 2012 - 02:23 AM

View PostMatthieu503, on 21 August 2012 - 08:15 PM, said:

So I tried it, heres what I did. It didn't redirect me to the next URL though
    Dim epoch = New DateTime(1970, 1, 1)
    Dim curTime = DateTime.Now
    Dim newTime = curTime.AddSeconds(21600000) 'Add 6 hours worth of milisecs.
    Dim newTime2 = My.Settings.Time
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer2.Interval = 3600000 'One hour worth of milisecs.
    End sub
    Private Sub WebBrowser4_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser4.DocumentCompleted
        If WebBrowser4.Url.ToString = "ArrivalURLHere" Then
            WebBrowser4.Navigate("http://AfterLinkHere")
            Timer2.Start()
            My.Settings.Time = curTime
            WebBrowser4.Hide()
            Label8.Hide()
            Label12.Show()
        End If
        Dim JobTime As String = TimeOfDay
    End Sub


    Private Sub WebBrowser3_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser3.DocumentCompleted

    End Sub

    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        Label12.Text = "Time When you can vote again" & curTime
        If curTime = newTime2 Then
            WebBrowser4.Show()
            Label8.Show()
            Label12.Hide()
        End If
    End Sub



I can't fully read the code as I'm on my iPad, but, have you assured you've created the timer? I'd set the timer interval straight after creating the timer, as I think that might be the problem. Also I'm not sure what is going on with all the hiding and showing stuff.

Will have a better look soon.
Was This Post Helpful? 0
  • +
  • -

#12 ToshNeox  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 100
  • Joined: 10-December 11

Re: A little Alarm for 6 Hours?

Posted 22 August 2012 - 07:37 AM

I just found from testing that Location is the position of the WebBrowser, so when I used a message box to show me the value, I got something like {X=12,Y=30}. Therefore you should use

WebBrowser4.Url.ToString()



However, I can't seem to get the WebBrowser to navigate anywhere - I think it might need to be in another sub, as I even tried stopping it first, waiting 200ms and then navigating, which still didn't work.
Was This Post Helpful? 0
  • +
  • -

#13 Matthieu503  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 21-August 12

Re: A little Alarm for 6 Hours?

Posted 22 August 2012 - 10:57 AM

Well the hiding and showing stuff, it is for it to disable them from doing it again, until the 6 hours has past. I'm going to try this later when I get home.
If WebBrowser4.Url.ToString("ArrivalLinkHere") Then
FunctionHere


Thanks for your help, I'll post back the results when i test it.
Was This Post Helpful? 0
  • +
  • -

#14 ToshNeox  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 100
  • Joined: 10-December 11

Re: A little Alarm for 6 Hours?

Posted 22 August 2012 - 11:06 AM

View PostMatthieu503, on 22 August 2012 - 10:57 AM, said:

Well the hiding and showing stuff, it is for it to disable them from doing it again, until the 6 hours has past. I'm going to try this later when I get home.
If WebBrowser4.Url.ToString("ArrivalLinkHere") Then
FunctionHere


Thanks for your help, I'll post back the results when i test it.


By the way that won't work as you're trying to use it as a function, it must be:

WebBrowser4.Url.ToString() = ""

Was This Post Helpful? 0
  • +
  • -

#15 Matthieu503  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 21-August 12

Re: A little Alarm for 6 Hours?

Posted 22 August 2012 - 12:25 PM

Is there another way to do this then?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2