我如何计算vb6表格中两个日期之间的星期五 [英] How do I count friday between two dates on vb6 form

查看:166
本文介绍了我如何计算vb6表格中两个日期之间的星期五的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的vb6表单中,我有2个DTPicker。现在我想在vb6表格上计算这两个日期之间的星期五



我尝试了什么:



我试着计算排除星期五如下。发生类型不匹配错误。



In my vb6 form I have 2 DTPicker. Now I want to count the Friday between this two dates on vb6 form

What I have tried:

I Have try to count exclude Friday as follow. Type mismatch error occurred.

Dim iDay As Long, i As Long, iWeekdays As Long

Date1 = f(DTPicker2.value)
Date2 = f(DTPicker6.value)
' loop through each date and check day
For i = 0 To DateDiff("d", Date1, Date2)
    iDay = Weekday(Date1 + i, vbSaturday)
    If iDay < 6 Then
        ' not Saturday or Sunday
        iWeekdays = iWeekdays + 1
    End If
Next i
Text3.Text = iWeekdays

推荐答案

你的逻辑错了!



Your logic is wrong!

If iDay < 6 Then





检查:



Check this:

If iDay <> 6 Then





有关详细信息,请参阅:工作日函数(Visual Basic) [ ^ ]



我将您的代码更改为:



For further details, please see: Weekday Function (Visual Basic)[^]

I'd change your code to:

For aDay = Date1 To Date2
    If WeekDay(aDay) <> 6 Then
        iDays = iDays + 1
    End If
Next aDay



其中 aDay 变量的类型为日期 iDays 的类型为整数


Where aDay variable is type of Date and iDays is type of Integer.


这篇关于我如何计算vb6表格中两个日期之间的星期五的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆