Oppure

Loading
Questo topic e' stato chiuso dal moderatore.
10/12/10 13:08
cbcup
Salve, ho incominciato a studiare le funzioni di Stopwatch e mi domandavo come posso associare, ad un cronometro, dei comandi che si avviino quando nella label dei secondi e/o minuti sia visualizzato un dato tempo? Ho provato con 'if labelX.text = XX then' ma questo, pur non dandomi alcun errore, non ha effetto.
Allego il codice che ho trovato ed un po modificato del crono a cui vorrei associare i comandi lanciandoli da diversi bottoni (es. Button5)

Grazie, Carlo.

Public Class Form1
    Dim watch As New Stopwatch

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Enabled = True
        watch.Start()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Enabled = False
        watch.Stop()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        watch.Reset()
        Label1.Text = "00"
        Label2.Text = "00"
        Label3.Text = "00"
        Label4.Text = "000"
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = String.Format("{0}", watch.Elapsed.Hours.ToString)
        Label2.Text = String.Format("{0}", watch.Elapsed.Minutes.ToString)
        Label3.Text = String.Format("{0}", watch.Elapsed.Seconds.ToString)
        Label4.Text = String.Format("{0}", watch.Elapsed.Milliseconds.ToString)
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Button3.PerformClick()
        Button1.PerformClick()
        If Label3.Text = 10 Then
            K8090.Connect()
            K8090.SwitchRelayOn(&HFF)
            K8090.Disconnect()
        End If
    End Sub

End Class
aaa
10/12/10 14:21
HeDo

la classe stopwatch server solo a misurare le peformances del codice in contesto di debugging o profiling, niente a che vedere con quello che vuoi fare te.
aaa
10/12/10 15:13
cbcup
Ho capito, grazie.
Bella fregatura.
Carlo.
aaa