【发布时间】:2014-12-22 12:06:06
【问题描述】:
我正在尝试使用Timer,效果很好我正在将它与其他变量一起使用
Const daily As Integer = 86400000
Const weekly As Integer = 604800000
Const hour As Integer = 3600000
但使用每月变量Private monthly As Long 时出现溢出错误,这是我的代码
Private timepick As New DateTimePicker()
Private timeLeft As Long
Public trackTimer As Long
Private CloseAllowed As Boolean
Private time As ULong
Private progress As Long
Const daily As Integer = 86400000
Const weekly As Integer = 604800000
Const hour As Integer = 3600000
Private monthly As Long
Private currentDate As Date = DateTime.Now
Private controller As Boolean = False
Private Sub AutoShutDown_Tick(sender As Object, e As EventArgs) Handles AutoShutDown.Tick
If (controller = False) Then
AutoShutDown.Enabled = False
Else
CountDown.Enabled = True
progress = 0
WarningForm.Timer1.Enabled = True
timeLeft = time
trackTimer = timeLeft
AutoShutDown.Interval = time 'Overflow
ProgressBar1.Maximum = timeLeft
End If
'System.Diagnostics.Process.Start("shutdown", "-s -t 00")
MsgBox("Shuting down...")
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
timepick.Format = DateTimePickerFormat.Time
timepick.ShowUpDown = True
timepick.Location = New Point(154, 12)
timepick.Width = 123
Me.Controls.Add(timepick)
cmbAction.SelectedIndex = 0
rdoOnce.Checked = True
Dim days As Long = DateTime.DaysInMonth(currentDate.Year, currentDate.Month)
monthly = (days * daily)
End Sub
我的Select Case的一部分
Case "Monthly"
Dim dueDate As Date = DateTime.Parse(currentDate.Month & "/" & cmbControl.Text & "/" & currentDate.Year & " " & timepick.Text)
Dim dayOfTheMonth As Integer = ((dueDate.Day * 24 - currentDate.Hour) * hour) + (dueDate.Minute * 60000) + (dueDate.Hour * hour)
Dim currentDayOfTheMon As Integer = ((currentDate.Day * 24 - currentDate.Hour) * hour) + (currentDate.Minute * 60000) + (currentDate.Hour * hour)
If (dayOfTheMonth > currentDayOfTheMon) Then
timeLeft = (dayOfTheMonth - currentDayOfTheMon)
End If
time = monthly
controller = True
End Select
trackTimer = timeLeft
ProgressBar1.Maximum = timeLeft
AutoShutDown.Interval = timeLeft
AutoShutDown.Enabled = True
CountDown.Enabled = True
【问题讨论】: