Datetime 在不使用查询的情况下比较时间

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

如何在不使用查询的情况下比较时间? 这是为了了解冲突 公共类TimeNo用于将时间转换为长时间 代码中还有一个错误,它表示byref参数类型不匹配错误

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)TimeNo(currentStartTime)))或((TimeNo(startTime)TimeNo(currentdime)),则 MsgBox“计划冲突”,VBE感叹号,“错误” Me.lstSchedules.ListItems.clear With Me.lstSchedules.ListItems.Add(,!SchoolLevel) .分项(1)=卢比!年度水平 .分项(2)=卢比!小节 .分项(3)=卢比!主题 .分项(4)=卢比!蒂梅因 .分项(5)=卢比!超时 .分项(6)=sH 以 如果结束 .下一步 环 其他的 getConflict=True 如果结束 以 端函数 公共函数TimeNo(时间为字符串)的长度 TimeNo=CLng(替换(格式(时间,“hhnnss”),“:”,“) 端函数
您的Dim声明不正确。只有endTime是日期,currentStartTime、currentEndTime和startTime都是变体。尝试每行仅调暗1个变量。此外,您正在向需要字符串的函数传递日期。谢谢,它起作用了。。但是我的时间检查冲突是对的吗?我不知道你的时间变量的值是什么。我可能会使用DateDiff函数并寻找重叠,但您的函数似乎按照您希望的方式工作,因此只需插入一些您知道不冲突的时间,有些时候,你知道数据类型是冲突的。日期数据类型的变量可以直接比较——为什么你有一个转换为Long的函数?如何直接比较日期数据类型?在比较日期数据类型方面,我仍然不够全面。。。所以我只是把它转换成长。。。请教我直接比较日期数据类型的方法。。。