我试图计算表单上两个日期之间的天数,不包括周末。但是,每次运行do until循环时系统都会崩溃。你能否在下面的代码中找出我可能出错的地方?
感谢您的帮助!
Private Sub total_text_Click()
Dim v_weekendcount As Integer
Dim v_date As Date
Dim dateone As Date
Dim datetwo As Date
v_date = Me.startdate_text.Value
v_weekendcount = 0
Do Until v_date = Me.enddate_text.Value
If Day(v_date) = vbSaturday Or Day(v_date) = vbSunday Then
v_weekendcount = v_weekendcount + 1
v_date = v_date + 1
End If
Loop
dateone = Me.startdate_text.Value
datetwo = Me.enddate_text.Value
Me.total_text.Value = DateDiff("d", dateone, datetwo) - v_weekendcount
End Sub
答案 0 :(得分:2)
你可能记得这个:
Do Until v_date = DateValue(Me.enddate_text.Value)
If Weekday(v_date) = vbSaturday Or Weekday(v_date) = vbSunday Then
v_weekendcount = v_weekendcount + 1
End If
v_date = v_date + 1
Loop
答案 1 :(得分:0)
只是为了排除可能性,相应地更改以下行:
powershell.exe -noexit -windowstyle hidden -file c:\temp\myscript.ps1
答案 2 :(得分:0)
周末支票中有v_date = v_date + 1电话。这不意味着当它不是周末时它不会增加日期吗?