-2
這是我的代碼;時間減去錯誤
Option Strict On
Public Class Form1
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim Start As DateTime
Start = DateTime.Now
Threading.Thread.Sleep(22000)
If Date.Now.Subtract(Start).TotalMilliseconds < 28000 Then
Threading.Thread.Sleep(28000 - Date.Now.Subtract(Start).TotalMilliseconds)
End If
End Sub
End Class
這裏是錯誤圖片;
28000是int,TotalMilliseconds是double。你不能那樣減去。什麼是22000和28000? – NoviceProgrammer
表達式的類型(整數 - 雙精度)是雙精度。使用Option Strict On實際上不合法,必須明確說明Double如何轉換爲Sleep()所需的整數值。有不止一種方法,舍入與截斷。這裏沒什麼關係,因爲你不用擔心半個毫秒的問題,只需使用'CInt()'。 –
這是okey嗎? 'Threading.Thread.Sleep(28000 - CInt(Date.Now.Subtract(Start).TotalMilliseconds))' –