2015年9月8日 星期二

vbnet 取年度週數

找了好久,都沒人處理取年度全部週數?!
只好自己來..
---


--
code:
Public Class Form1

    Private Function getDateFromYrWkDays(ByVal YYYY, ByVal Wks, ByVal WkDays) As Date
        Dim d As Date
        d = CDate(YYYY & "/1/1")
        getDateFromYrWkDays = d.AddDays(WkDays - d.DayOfWeek + (Wks - 1) * 7)
    End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim d1 As Date
        Dim d2 As Date
        Dim y1 As Integer = 2015
        '--
        CombBWeek.Items.Clear()
        For i As Integer = 1 To 52
            d1 = getDateFromYrWkDays(y1, i, 1)
            d2 = getDateFromYrWkDays(y1, i, 7)
            CombBWeek.Items.Add("第" & Format(i, "00") & "週," & d1 & "," & d2)
        Next
    End Sub
End Class

沒有留言:

張貼留言