gpt4 book ai didi

vb6 - 如何在 Visual Basic 6 中查找给定日期的周数?

转载 作者:行者123 更新时间:2023-12-03 14:07:17 26 4
gpt4 key购买 nike

有没有人在 vb6 中返回给定日期的周数的工作函数?

这曾经有效:

Dim W As Integer

W = Format(DateSerial(2010, 1, 1), "ww", vbMonday, vbFirstFourDays)

但是在 Windows 8.1 中,您现在得到“堆栈空间不足”。

最佳答案

鉴于偏移量,答案有点复杂

以下功能应该可以很好地满足您的需求。只需将一个有效的 Date 对象传递给它,它就会返回一个周数的整数。

Private Function Week(dteValue As Date) As Integer
'Monday is set as first day of week
Dim lngDate As Long
Dim intWeek As Integer

'If january 1. is later then thursday, january 1. is not in week 1
If Not Weekday("01/01/" & Year(dteValue), vbMonday) > 4 Then
intWeek = 1
Else
intWeek = 0
End If
'Sets long-value for january 1.
lngDate = CLng(CDate("01/01/" & Year(dteValue)))

'Finds the first monday of year
lngDate = lngDate + (8 - Weekday("01/01/" & Year(dteValue), vbMonday))
'Increases week by week until set date is passed
While Not lngDate > CLng(CDate(dteValue))
intWeek = intWeek + 1
lngDate = lngDate + 7
Wend
'If the date set is not in week 1, this finds latest week previous year
If intWeek = 0 Then
intWeek = Week("31/12/" & Year(dteValue) - 1)
End If
Week = intWeek
End Function

此代码由 FreeVBCode.com 友情提供(包括引用以赋予原作者属性)。

关于vb6 - 如何在 Visual Basic 6 中查找给定日期的周数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21689173/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com