标题: 公司的工厂日历的模块代码,进行修改规整 [打印本页] 作者: yanwei82123300 时间: 2010-10-8 16:32 标题: 公司的工厂日历的模块代码,进行修改规整 下面是我公司的工厂日历的模块代码:它是有规律的每一个P几都是开始日期和结束日期减
请问有没有办法写一段万年历是的代码,免去每次都需要更改里面的日期的代码。
谢谢
Fisher2010年工厂日历
Function GetP(a As Date) As String
Dim Re As String
If a >= CDate("2009-10-1") And a <= CDate("2009-10-23") Then
Re = "2010_P1"
ElseIf a >= CDate("2009-10-24") And a <= CDate("2009-11-20") Then
Re = "2010_P2"
ElseIf a >= CDate("2009-11-21") And a <= CDate("2009-12-25") Then
Re = "2010_P3"
ElseIf a >= CDate("2009-12-26") And a <= CDate("2010-01-22") Then
Re = "2010_P4"
ElseIf a >= CDate("2010-01-23") And a <= CDate("2010-02-19") Then
Re = "2010_P5"
ElseIf a >= CDate("2010-02-20") And a <= CDate("2010-03-26") Then
Re = "2010_P6"
ElseIf a >= CDate("2010-03-27") And a <= CDate("2010-04-23") Then
Re = "2010_P7"
ElseIf a >= CDate("2010-04-24") And a <= CDate("2010-05-21") Then
Re = "2010_P8"
ElseIf a >= CDate("2010-05-22") And a <= CDate("2010-06-25") Then
Re = "2010_P9"
ElseIf a >= CDate("2010-06-26") And a <= CDate("2010-07-23") Then
Re = "2010_P10"
ElseIf a >= CDate("2010-07-24") And a <= CDate("2010-08-20") Then
Re = "2010_P11"
ElseIf a >= CDate("2010-08-21") And a <= CDate("2010-09-30") Then
Re = "2010_P12"
Else
End If
GetP = Re
End Function
Fisher2011年工厂日历
Function GetP(A As Date) As String
Dim Re As String
If A >= CDate("2010-10-1") And A <= CDate("2010-10-22") Then
Re = "2011_P1"
ElseIf A >= CDate("2010-10-23") And A <= CDate("2010-11-19") Then
Re = "2011_P2"
ElseIf A >= CDate("2010-11-20") And A <= CDate("2010-12-24") Then
Re = "2011_P3"
ElseIf A >= CDate("2010-12-25") And A <= CDate("2011-01-21") Then
Re = "2011_P4"
ElseIf A >= CDate("2011-01-22") And A <= CDate("2011-02-18") Then
Re = "2011_P5"
ElseIf A >= CDate("2011-02-19") And A <= CDate("2011-03-25") Then
Re = "2011_P6"
ElseIf A >= CDate("2011-03-26") And A <= CDate("2011-04-22") Then
Re = "2011_P7"
ElseIf A >= CDate("2011-04-23") And A <= CDate("2011-05-20") Then
Re = "2011_P8"
ElseIf A >= CDate("2011-05-21") And A <= CDate("2011-06-24") Then
Re = "2011_P9"
ElseIf A >= CDate("2011-06-25") And A <= CDate("2011-07-22") Then
Re = "2011_P10"
ElseIf A >= CDate("2011-07-23") And A <= CDate("2011-08-19") Then
Re = "2011_P11"
ElseIf A >= CDate("2011-08-20") And A <= CDate("2011-09-30") Then
Re = "2011_P12"
Else
End If
GetP = Re
End Function
Fisher2012年工厂日历
Function GetP(A As Date) As String
Dim Re As String
If A >= CDate("2011-10-1") And A <= CDate("2011-10-21") Then
Re = "2012_P1"
ElseIf A >= CDate("2011-10-22") And A <= CDate("2011-11-18") Then
Re = "2012_P2"
ElseIf A >= CDate("2011-11-19") And A <= CDate("2011-12-23") Then
Re = "2012_P3"
ElseIf A >= CDate("2010-12-24") And A <= CDate("2012-01-20") Then
Re = "2012_P4"
ElseIf A >= CDate("2012-01-21") And A <= CDate("2012-02-17") Then
Re = "2012_P5"
ElseIf A >= CDate("2012-02-18") And A <= CDate("2012-03-24") Then
Re = "2012_P6"
ElseIf A >= CDate("2012-03-25") And A <= CDate("2012-04-21") Then
Re = "2012_P7"
ElseIf A >= CDate("2012-04-22") And A <= CDate("2012-05-19") Then
Re = "2012_P8"
ElseIf A >= CDate("2012-05-20") And A <= CDate("2012-06-23") Then
Re = "2012_P9"
ElseIf A >= CDate("2012-06-24") And A <= CDate("2012-07-21") Then
Re = "2012_P10"
ElseIf A >= CDate("2012-07-22") And A <= CDate("2012-08-18") Then
Re = "2012_P11"
ElseIf A >= CDate("2012-08-19") And A <= CDate("2012-09-30") Then
Re = "2012_P12"
Else
End If
GetP = Re
End Function 作者: hjb016 时间: 2010-10-8 17:42
谢谢分享作者: todaynew 时间: 2010-10-8 20:01 本帖最后由 todaynew 于 2010-10-8 20:03 编辑
Function Calendar3(Ddate As Date) As String
'功能:每季度按445周的的工厂日历
Dim Mydate As Date
Dim str As String
Dim i As Long, j As Long, m
'计算第一个结账月
Mydate = DateSerial(Ddate - 1, 10, 1)
str = str & 1 & ";" & Mydate & ";"
If Weekday(Mydate, vbMonday) <> 6 Then
Mydate = DateAdd("d", 21, Mydate)
For j = 1 To 7
If Weekday(Mydate, vbMonday) = 5 Then
Exit For
End If
Mydate = DateAdd("d", 1, Mydate)
Next
Else
Mydate = DateAdd("d", 20, Mydate)
End If
str = str & Mydate & ";"
'计算2至11结算月,每季度中个月周数按445计算
m = 0
For i = 1 To 4
For j = 1 To 3
m = m + 1
If m = 12 Then Exit For
If m <> 1 Then
str = str & m & ";" & DateAdd("d", 1, Mydate) & ";"
If j <> 3 Then
Mydate = DateAdd("d", 28, Mydate)
Else
Mydate = DateAdd("d", 35, Mydate)
End If
str = str & Mydate & ";"
End If
Next
If m = 12 Then Exit For
Next
'计算最后一个结算月
str = str & m + 1 & ";" & DateAdd("d", 1, Mydate) & ";" & DateSerial(Ddate, 9, 30)
Function Calendar(Myyear As Long) As String
'功能:每季度按445周的的工厂日历
'参数:Myyear--财政年度
'示例:Me.日历.RowSource = "月度;首日;末日;" & Calendar(Me.年度.Value)
Dim mydate As Date
Dim str As String
Dim i As Long, j As Long, m
mydate = DateSerial(Myyear - 1, 10, 1)
str = str & 1 & ";" & mydate & ";"
If Weekday(mydate, vbMonday) <> 6 Then
mydate = DateAdd("d", 21, mydate)
For j = 1 To 7
If Weekday(mydate, vbMonday) = 5 Then
Exit For
End If
mydate = DateAdd("d", 1, mydate)
Next
Else
mydate = DateAdd("d", 20, mydate)
End If
str = str & mydate & ";"
m = 0
For i = 1 To 4
For j = 1 To 3
m = m + 1
If m = 12 Then Exit For
If m <> 1 Then
str = str & m & ";" & DateAdd("d", 1, mydate) & ";"
If j <> 3 Then
mydate = DateAdd("d", 28, mydate)
Else
mydate = DateAdd("d", 35, mydate)
End If
str = str & mydate & ";"
End If
Next
If m = 12 Then Exit For
Next
str = str & m & ";" & DateAdd("d", 1, mydate) & ";" & DateSerial(Myyear, 9, 30)
Calendar = str
End Function
Function mnth(mydate As Date) As Variant
'功能:按日历日期返回财政日历数组
'参数:mydate--日历日期
'示例:
'Dim A
'If IsDate(Me.日历日期) = True Then
'A=mnth(Me.日历日期.Value)
'Me.财政年度.Value = A(0)
'Me.财政月度.Value =A(1)
'Me.首日.Value = A(2)
'Me.末日.Value = A(3)
'Else
'MsgBox "日历日期不能为空!"
'End If
Dim str As String
Dim myMonth As Long
Dim A
Dim B(4)
Dim date0 As Date, date1 As Date
Dim i As Long
If Month(mydate) >= 10 And Month(mydate) <= 12 Then
str = Calendar(Year(mydate) + 1)
B(0) = Year(mydate) + 1
Else
str = Calendar(Year(mydate))
B(0) = Year(mydate)
End If
A = Split(str, ";")
For i = 0 To UBound(A, 1) Step 3
myMonth = A(i)
date0 = CDate(A(i + 1))
date1 = CDate(A(i + 2))
If CDate(mydate) >= date0 And CDate(mydate) <= date1 Then
B(2) = date0: B(3) = date1
Exit For
End If
Next
B(1) = myMonth
mnth = B
End Function
Function Calendar(Myyear As Long) As String
'功能:每季度按445周的的工厂日历
'参数:Myyear--财政年度
'示例:Me.日历.RowSource = "月度;首日;末日;" & Calendar(Me.年度.Value)
Dim mydate As Date
Dim str As String
Dim i As Long, j As Long, m
mydate = DateSerial(Myyear - 1, 10, 1)
str = str & 1 & ";" & mydate & ";"
If Weekday(mydate, vbMonday) <> 6 Then
mydate = DateAdd("d", 21, mydate)
For j = 1 To 7
If Weekday(mydate, vbMonday) = 5 Then
Exit For
End If
mydate = DateAdd("d", 1, mydate)
Next
Else
mydate = DateAdd("d", 20, mydate)
End If
str = str & mydate & ";"
m = 0
For i = 1 To 4
For j = 1 To 3
m = m + 1
If m = 12 Then Exit For
If m <> 1 Then
str = str & m & ";" & DateAdd("d", 1, mydate) & ";"
If j <> 3 Then
mydate = DateAdd("d", 28, mydate)
Else
mydate = DateAdd("d", 35, mydate)
End If
str = str & mydate & ";"
End If
Next
If m = 12 Then Exit For
Next
str = str & m & ";" & DateAdd("d", 1, mydate) & ";" & DateSerial(Myyear, 9, 30)
Calendar = str
End Function
Function mnth(mydate As Date) As Variant
'功能:按日历日期返回财政日历数组
'参数:mydate--日历日期
'示例:
'
'select *,mnth(订单日期)(0) as 财政年,mnth(订单日期)(1) as 财政月,mnth(订单日期)(4) as 周 from 订单表
Dim str As String
Dim myMonth As Long
Dim A
Dim B(5)
Dim date0 As Date, date1 As Date
Dim i As Long
If Month(mydate) >= 10 And Month(mydate) <= 12 Then
str = Calendar(Year(mydate) + 1)
B(0) = Year(mydate) + 1
Else
str = Calendar(Year(mydate))
B(0) = Year(mydate)
End If
A = Split(str, ";")
For i = 0 To UBound(A, 1) Step 3
myMonth = A(i)
date0 = CDate(A(i + 1))
date1 = CDate(A(i + 2))
If CDate(mydate) >= date0 And CDate(mydate) <= date1 Then
B(2) = date0: B(3) = date1
B(4) = DateDiff("ww", date0, mydate)
Exit For
End If
Next
B(1) = myMonth
mnth = B
End Function