2016-03-05 18 views
0

這場景,我有三個NumericUpDown爲第二,分鐘和小時值,而如果在NumericUpDown5輸入一個數字,它會被轉換爲​​所以我的Timer可以讀取它5秒。我試圖讓每一個間隔調度,這是我的代碼:VB.NET如何添加入庫時間定時器Inteval

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 

    Label13.Text = TimeSpan.FromSeconds(Form3.NumericUpDown1.Text).TotalMilliseconds 
    Label14.Text = TimeSpan.FromMinutes(Form3.NumericUpDown2.Text).TotalSeconds 
    Label15.Text = TimeSpan.FromHours(Form3.NumericUpDown3.Text).TotalMinutes 

    Dim times() As String = {Label13.Text, Label14.Text, Label15.Text} 

    For Each time In times 
     Dim interval As TimeSpan = TimeSpan.Parse(time) 

      Timer1.Interval = interval 
      MsgBox("hey") 
    Next 
End Sub 

它在Timer1.Interval = interval,說Timespan cannot be converted to Integer有錯誤,我想不出什麼辦法來解決這個問題,你可以幫幫我? TIA〜!

+0

你想在這裏什麼也不是那麼清楚。假如你的'NumericUpDown1.Text = 5','NumericUpDown2.Text = 15','NumericUpDown3.Text = 25',你希望它的行爲如何? – Ian

回答

0

嘗試這個

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick 

Timer1.Stop() 

Timer1.Interval = New TimeSpan(0, 0, CInt(nudMinutes.Value), CInt(nudSeconds.Value), CInt(nudMilliseconds.Value)).TotalMilliseconds 

Timer1.Start() 

End Sub 
0

這裏有一些想法讓你過去你目前的錯誤。

Dim tsTest As TimeSpan = TimeSpan.FromSeconds(NumericUpDownTest.Value) 

    Label1.Text = tsTest.TotalSeconds.ToString("n0") 

    Timer1.Interval = CInt(tsTest.TotalMilliseconds) 

開始只是做秒,當代碼工作看看你是否可以添加其他人。

相關問題