Copyright © 2003-2009
By Suthep Sangvirotjanaphat
  Mobile: 089-967-2200, 081-915-7816
Phone: 0-2992-4877   Fax: 0-2992-4878
Fast Contact Us

GreatFriends.Biz Community

Custom Search
Copy เพื่ออ้างอิงถึงข้อความนี้:
 MESSAGE #8960 (อ่าน 1,071 ครั้ง)

คำนวน หาวันทั้งหมด ในเดือน ....

อาจารย์ครับ  ผมต้องการจะหาว่า
ในแต้ละเดือน มีจำนวนวันกี่วัน ผมจะหาได้ยังงัยครับ

ฝากอาจารย์ตอบด้วยครับ ขอบคุณล่วงหน้าครับ


นาย วันที่ส่ง: 24 มี.ค. 48 06:02 GMT+7
วันที่ปรับล่าสุด: 24 มี.ค. 48 08:45 GMT+7
REPLY #1 (8962)
.NET Framework Base Class Library (BCL) อุดมไปด้วยคลาสจำนวนมาก
เราอาจจะแปลกใจถ้าทราบว่ามีคลาสหนึ่งมีชื่อเต็มๆ ว่า

System.Globalization.ThaiBuddhistCalendar


สิ่งที่คุณนายถามมาให้ใช้เมธอดชื่อ GetDaysInMonth ตามตัวอย่างนี้ครับ

[codevb]Imports System.Globalization
...
Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
    Dim b As New ThaiBuddhistCalendar
    Dim s As String

    For y As Integer = 2548 To 2551
        Debug.WriteLine("Year " & y)
        For m As Integer = 1 To 12
            s = String.Format("  Month {0} has {1} days.", m, b.GetDaysInMonth(y, m))
            Debug.WriteLine(s)
        Next m
    Next y
End Sub[/codevb]

ผลลัพธ์จากการรันโค้ด:

Year 2548
  Month 1 has 31 days.
  Month 2 has 28 days.
  Month 3 has 31 days.
  Month 4 has 30 days.
  Month 5 has 31 days.
  Month 6 has 30 days.
  Month 7 has 31 days.
  Month 8 has 31 days.
  Month 9 has 30 days.
  Month 10 has 31 days.
  Month 11 has 30 days.
  Month 12 has 31 days.
Year 2549
  Month 1 has 31 days.
  Month 2 has 28 days.
  Month 3 has 31 days.
  Month 4 has 30 days.
  Month 5 has 31 days.
  Month 6 has 30 days.
  Month 7 has 31 days.
  Month 8 has 31 days.
  Month 9 has 30 days.
  Month 10 has 31 days.
  Month 11 has 30 days.
  Month 12 has 31 days.
Year 2550
  Month 1 has 31 days.
  Month 2 has 28 days.
  Month 3 has 31 days.
  Month 4 has 30 days.
  Month 5 has 31 days.
  Month 6 has 30 days.
  Month 7 has 31 days.
  Month 8 has 31 days.
  Month 9 has 30 days.
  Month 10 has 31 days.
  Month 11 has 30 days.
  Month 12 has 31 days.
Year 2551
  Month 1 has 31 days.
  Month 2 has 29 days.
  Month 3 has 31 days.
  Month 4 has 30 days.
  Month 5 has 31 days.
  Month 6 has 30 days.
  Month 7 has 31 days.
  Month 8 has 31 days.
  Month 9 has 30 days.
  Month 10 has 31 days.
  Month 11 has 30 days.
  Month 12 has 31 days.



นอกจากเมธอด GetDaysInMonth แล้ว
ยังมี member ของคลาส ThaiBuddhistCalendar
ที่น่าสนใจอีกหลายตัวนะครับ เช่น IsLeapYear() และ IsLeapDay()



surrealist วันที่ส่ง: 24 มี.ค. 48 07:21 GMT+7
วันที่ปรับล่าสุด: 24 มี.ค. 48 07:21 GMT+7
REPLY #2 (8968)
ขอบคุณมากครับอาจารย์ แบบของอาจารย์ ใช้ .net framework
บังเอิญผมมีแบบใช้ function ครับบังเอิญไปค้นเจอมา

'

Public Function GetLastDay(ByVal aDate As Date) As Day

    Return DateSerial(Year(aDate), Month(aDate) + 1, 1 - 1).Day

End Function

ปะมานนี้อ่ะคับ หุหุหุ



นาย วันที่ส่ง: 24 มี.ค. 48 08:45 GMT+7
วันที่ปรับล่าสุด: 24 มี.ค. 48 08:45 GMT+7
กระทู้นี้มีอายุเกิน 365 วันแล้ว ท่านจะไม่สามารถตอบกระทู้นี้ได้อีก
ถ้าต้องการสนทนาต่อ กรุณาตั้งเป็นกระทู้ใหม่ได้ในหน้าโฮม
และอาจจะอ้างถึงกระทู้นี้ โดยก๊อปปี้ข้อความในกล่องสีขาวด้านล่างไปแปะในกระทู้ใหม่

copy เพื่ออ้างอิงถึงข้อความนี้:
คำนวน หาวันทั้งหมด ในเดือน ....
http://greatfriends.biz?8960


4 ก.ย. 00:53
Online: 228