4 Replies - 231 Views - Last Post: 01 May 2019 - 07:38 AM

#1 DarenR   User is offline

  • D.I.C Lover

Reputation: 602
  • View blog
  • Posts: 3,993
  • Joined: 12-January 10

how to automatically keep refreshing the time stamp?

Posted 01 May 2019 - 04:58 AM

i have added a timer but the time stamp doesnt seem to auto update:

code:
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      
        LoadValues()
        AddHandler Timer1.Elapsed, AddressOf OnTimedEvent
        Timer1.Enabled = True

    End Sub
    Private Sub OnTimedEvent(source As Object, e As ElapsedEventArgs)
        If DateTime.Now.Minute = 0 and Timer1.Interval <> 3600000 Then
            Timer1.Interval = 3600000
        else
            updateTime()
        End If
    End Sub
    Private sub Timer1_Tick(sender As Object, e As System.EventArgs)
        updateTime()
    End sub
    Protected sub updateTime()
        if Not IsPostBack then
            txtHourlyTime.Text = DateTime.Now.ToShortTimeString()
        end if
    End sub



as you can see there are 2 different ways i tried updating the timestamp but nope

Is This A Good Question/Topic? 0
  • +

Replies To: how to automatically keep refreshing the time stamp?

#2 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,050
  • Joined: 12-December 12

Re: how to automatically keep refreshing the time stamp?

Posted 01 May 2019 - 05:24 AM

You have not Start()'ed the timer.
Was This Post Helpful? 0
  • +
  • -

#3 DarenR   User is offline

  • D.I.C Lover

Reputation: 602
  • View blog
  • Posts: 3,993
  • Joined: 12-January 10

Re: how to automatically keep refreshing the time stamp?

Posted 01 May 2019 - 05:38 AM

enabled starts the timer in vb-- i can watch it cycle the time it just doesnt update the textbox
Was This Post Helpful? 0
  • +
  • -

#4 dbasnett   User is offline

  • D.I.C Addict
  • member icon

Reputation: 122
  • View blog
  • Posts: 679
  • Joined: 01-October 08

Re: how to automatically keep refreshing the time stamp?

Posted 01 May 2019 - 07:34 AM

Is this Windows Forms? Is IsPostBack False? What is Timer1? What is the initial value of Timer1.Interval? I did this to see if in general what you have works, and this does work.

Public Class Form1

    Private IsPostBack As Boolean = False
    Private WithEvents Timer1 As New System.Timers.Timer(500)

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        AddHandler Timer1.Elapsed, AddressOf OnTimedEvent
        Timer1.Enabled = True
    End Sub

    Private Sub OnTimedEvent(source As Object, e As Timers.ElapsedEventArgs)
        If Timer1.Interval <> 3600000 AndAlso DateTime.Now.Minute = 0 Then
            Timer1.Interval = 3600000
        Else
            updateTime()
        End If
    End Sub

    Protected Sub updateTime()
        If Not IsPostBack Then
            Me.BeginInvoke(Sub()
                               ' txtHourlyTime.Text = DateTime.Now.ToShortTimeString()
                               txtHourlyTime.Text = DateTime.Now.ToString("HH:mm:ss")
                           End Sub)
        End If
    End Sub

End Class


Was This Post Helpful? 0
  • +
  • -

#5 DarenR   User is offline

  • D.I.C Lover

Reputation: 602
  • View blog
  • Posts: 3,993
  • Joined: 12-January 10

Re: how to automatically keep refreshing the time stamp?

Posted 01 May 2019 - 07:38 AM

its an asp.net page and i have solved it by putting the item in an updatepanel

 <asp:UpdatePanel runat="server" id="updatePnl" UpdateMode="Conditional" >
                   <ContentTemplate>
                    <div class="divControls7">
                        <div class="divControls2"> <asp:Label runat="server" ID="lblTransTime" CssClass="labelNormal" text="TRAN TIME: "></asp:Label></div>
                        <div class="divControls3"> <asp:TextBox runat="server" id="txtHourlyTime" CssClass="textboxStyle3"></asp:TextBox> </div>
                    </div>
                        <asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick ="Timer1_Tick"></asp:Timer>
                        </ContentTemplate>
                    </asp:UpdatePanel>



code behind

 private sub UpdateServerTime()
        txtHourlyTime.Text= DateTime.Now.ToShortTimeString()
    end sub
    protected sub Timer1_Tick(sender As Object, e As System.EventArgs)
    
         UpdateServerTime()
    
    end sub

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1