Datetime 在不使用查询的情况下比较时间
如何在不使用查询的情况下比较时间? 这是为了了解冲突 公共类TimeNo用于将时间转换为长时间 代码中还有一个错误,它表示byref参数类型不匹配错误Datetime 在不使用查询的情况下比较时间,datetime,vb6,Datetime,Vb6,如何在不使用查询的情况下比较时间? 这是为了了解冲突 公共类TimeNo用于将时间转换为长时间 代码中还有一个错误,它表示byref参数类型不匹配错误 Function getConflict() As Boolean Me.lstSchedules.ListItems.clear Dim currentStartTime, currentEndTime, startTime, endTime As Date Set rs = Nothing currentStartTime = Me.cbo
Function getConflict() As Boolean
Me.lstSchedules.ListItems.clear
Dim currentStartTime, currentEndTime, startTime, endTime As Date
Set rs = Nothing
currentStartTime = Me.cboTime.Text
currrentendtime = Me.cboEnd.Text
With rs
.CursorLocation = adUseClient
.Open "select * from tblSecSched where Sections = '" & Me.cboSection.Text & "' and [Day] = '" & Me.cboDay.Text & "' and SchoolLevel = '" & Me.cboSchoolLevel.Text & "' and YearLevel = '" & Me.cboYearLevel.Text & "' and SchoolYear = '" & sH & "'", cs, 1, 2
If .RecordCount > 0 Then
getConflict = False
Do While Not .EOF
startTime = CDate(!TimeIn)
endTime = CDate(!TimeOut)
If ((TimeNo(startTime) < TimeNo(currentStartTime)) And (TimeNo(endTime) > TimeNo(currentStartTime))) Or ((TimeNo(startTime) < TimeNo(currentEndTime)) And (TimeNo(endTime) > TimeNo(currentEndTime))) Then
MsgBox "Schedule Conflict", vbExclamation, "ERROR"
Me.lstSchedules.ListItems.clear
With Me.lstSchedules.ListItems.Add(, , !SchoolLevel)
.SubItems(1) = rs!YearLevel
.SubItems(2) = rs!Sections
.SubItems(3) = rs!Subject
.SubItems(4) = rs!TimeIn
.SubItems(5) = rs!TimeOut
.SubItems(6) = sH
End With
End If
.MoveNext
Loop
Else
getConflict = True
End If
End With
End Function
Public Function TimeNo(Time As String) As Long
TimeNo = CLng(Replace(Format(Time, "hhnnss"), ":", ""))
End Function
函数getConflict()为布尔值
Me.lstSchedules.ListItems.clear
Dim currentStartTime、currentEndTime、startTime、endTime作为日期
设置rs=无
currentStartTime=Me.cboTime.Text
currentendtime=Me.cboEnd.Text
用rs
.CursorLocation=adUseClient
.打开“从TBLSECSCCHED中选择*,其中Sections='”&Me.cboSection.Text&'”和[Day]='“&Me.cboDay.Text&'”和schoolevel='”&Me.cboSchoolLevel.Text&“'和YearLevel='&Me.cboYearLevel.Text&'”和学年='&sH&',cs,1,2
如果.RecordCount>0,则
getConflict=False
做而不做
startTime=CDate(!TimeIn)
endTime=CDate(!超时)
如果((TimeNo(startTime)您的Dim声明不正确。只有endTime是日期,currentStartTime、currentEndTime和startTime都是变体。尝试每行仅调暗1个变量。此外,您正在向需要字符串的函数传递日期。谢谢,它起作用了。。但是我的时间检查冲突是对的吗?我不知道你的时间变量的值是什么。我可能会使用DateDiff函数并寻找重叠,但您的函数似乎按照您希望的方式工作,因此只需插入一些您知道不冲突的时间,有些时候,你知道数据类型是冲突的。日期数据类型的变量可以直接比较——为什么你有一个转换为Long的函数?如何直接比较日期数据类型?在比较日期数据类型方面,我仍然不够全面。。。所以我只是把它转换成长。。。请教我直接比较日期数据类型的方法。。。