..:: Diễn đàn lớp 07CK2 - ĐH.KHTN - TP.HCM ::..
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.
Lời Hay Ý Đẹp
Latest topics
» Tự học lập trình IOS trong vòng 24h
by kenanh 27/1/2014, 22:28

» xin tài liệu một số môn học
by nguyentvvan 21/8/2013, 21:34

» [Thảo luận] Bài toán đong nước
by giathinh9x 9/1/2013, 22:39

» Học Marketing Online, Học Chuyên viên Internet Marketing Online tại iNET
by NIIT-iNET 19/6/2012, 14:23

» Học PHP nâng cao, Học lập trình web với PHP nâng cao tại học viện iNET
by NIIT-iNET 19/6/2012, 14:22

» Học PHP, học lập trình web với PHP tại iNET vào ngày 19/07/2012
by NIIT-iNET 19/6/2012, 14:20

» PHIÊN BẢN MỚI CHO THIÊN ĐƯỜNG CÁ Ô LA LA !!!
by todaytv 13/3/2012, 15:35

» [hot] game khu vườn địa đàng phiên bản mobile của KVTM
by trantinh1713 3/1/2012, 15:20

» Đề tham khảo (update phút 90)
by ndc_2209 29/12/2011, 10:26

» Học bổng Lời Dịch tuần này.
by tienganh123 1/11/2011, 13:13

» [Thảo luận] Quản lý phân công giảng dạy PTTH
by huyquang0510 5/10/2011, 09:52

» Học tiếng Nhật - Top Globis
by tuquynh 21/9/2011, 10:35

» Học tiếng Nhật - Top Globis
by tuquynh 8/8/2011, 11:19

» Order Imitrex Online
by Khách viếng thăm 4/8/2011, 18:46

» Speeds Caffeine Metabolism Up
by Khách viếng thăm 4/8/2011, 18:12

» Skin For Good Caffeine
by Khách viếng thăm 3/8/2011, 14:54

» Cheap Pvc Figures
by Khách viếng thăm 1/8/2011, 19:32

» Action Rapid Onset Zolpidem Of
by Khách viếng thăm 31/7/2011, 01:13

» TUYỂN NHÂN VIÊN KINH DOANH ( làm việc tại văn phòng )
by canhkientp 5/7/2011, 14:59

» Demo + Vài điểm thảo luận về LINQ - Nhóm 7
by ChuongTienPhat 3/7/2011, 12:19


code ngày tháng

Go down

code ngày tháng Empty code ngày tháng

Bài gửi by TranNgocSang 10/11/2009, 07:29

'bài 593: khai báo dữ liệu kiểu ngày tháng
Structure Ngay_Thang
Dim Ngay As Integer
Dim Thang As Integer
Dim Nam As Integer
End Structure
'bài 594: nhập ngày tháng
Sub Nhap_Ngay_Thang(ByRef A As Ngay_Thang)

Console.Write("Nhap vao nam: ")
A.Nam = Console.ReadLine()

Console.Write("Nhap vao thang: ")
A.Thang = Console.ReadLine()

Console.Write("Nhap vao ngay: ")
A.Ngay = Console.ReadLine()

End Sub
'bài 595: xuất ngày tháng theo định dạng d/m/y
Sub Xuat_Ngay_Thang(ByVal A As Ngay_Thang)
Console.Write(A.Ngay & "/" & A.Thang & "/" & A.Nam)
End Sub
'bài 596: kiểm tra năm nhuần
Function Kiem_Tra_Nam_Nhuan(ByVal A As Ngay_Thang) As Boolean
While (A.Nam <> 0)
A.Nam = A.Nam \ 4
If (A.Nam = 1) Then
Return True
End If
End While
Return False
End Function
'bài 597: Tính số thứ tự ngày trong năm
Function Tinh_So_Thu_Tu_Ngay_Trong_Nam(ByVal ngay As Integer, ByVal thang As Integer) As Integer
Dim A() As Integer = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim i As Integer = 0
While (i < thang)
ngay = ngay + A(i)
i = i + 1
End While
Return ngay
End Function
'bài 598: Tính số thứ tự từ ngày 1/1/1
Function Tinh_So_Thu_Tu_Ngay_Ke_Tu_1_1_1(ByVal ngay As Integer, ByVal thang As Integer, ByVal nam As Integer)
Dim so_ngay_moi_thang_cua_nam_thuong() As Integer = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim so_ngay_moi_thang_cua_nam_nhuan() As Integer = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim tong_so_ngay_trong_nam_nhuan As Integer = 366
Dim tong_so_ngay_trong_nam_thuong As Integer = 365
Dim n As Integer = 1
While (n <= nam)

'neu toi nam hien hanh
If (n = nam) Then
Dim t As Integer = 1
'neu la nam nhuan
If (n Mod 4 = 0) Then
While (t < thang)
ngay = ngay + so_ngay_moi_thang_cua_nam_nhuan(t)
t = t + 1
End While
'neu la nam thuong
Else
While (t < thang)
ngay = ngay + so_ngay_moi_thang_cua_nam_thuong(t)
t = t + 1
End While

End If
Else
'neu chua toi nam hien hanh
If (n Mod 4 = 0) Then
ngay = ngay + tong_so_ngay_trong_nam_nhuan
Else
ngay = ngay + tong_so_ngay_trong_nam_thuong
End If
End If
n = n + 1
End While
Return ngay
End Function
'bài 599: Tỉm ngày khi biết năm và số thứ tự trong năm
Function Tim_Ngay_Khi_Biet_Nam_Va_So_Thu_Tu_Cua_Ngay_Trong_Nam(ByVal Nam As Integer, ByVal so_thu_tu_ngay As Integer) As Integer
Dim ngay As Integer = so_thu_tu_ngay
Dim so_ngay_moi_thang_cua_nam_thuong() As Integer = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim so_ngay_moi_thang_cua_nam_nhuan() As Integer = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
If (Nam Mod 4 = 0) Then
Dim i As Integer = 1
While (ngay > so_ngay_moi_thang_cua_nam_nhuan(i))
ngay = ngay - so_ngay_moi_thang_cua_nam_nhuan(i)
i = i + 1
End While
Else
Dim i As Integer = 1
While (ngay > so_ngay_moi_thang_cua_nam_thuong(i))
ngay = ngay - so_ngay_moi_thang_cua_nam_thuong(i)
i = i + 1
End While
End If
Return ngay
End Function
'bài 600: tìm ngày khi biết số thứ tự của ngày kể từ 1/1/1
Function Tim_Ngay_Khi_Biet_So_Thu_Tu_Ke_Tu_Ngay_1_1_1(ByVal sttn As Integer) As Integer
Dim n As Integer = 1
While ((n Mod 4 = 0 And sttn > 366) Or (n Mod 4 <> 0 And sttn > 365))
If (n Mod 4 = 0) Then
sttn = sttn - 366
Else
sttn = sttn - 365
End If
n = n + 1
End While
Dim A() As Integer = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim B() As Integer = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim i As Integer = 1
While (sttn > A(i) Or sttn > B(i))
If (n Mod 4 = 0) Then
sttn = sttn - B(i)
Else
sttn = sttn - A(i)
End If
i = i + 1
End While
Return sttn
End Function
'bài 601: tìm ngày kế tiếp
Function Tim_Ngay_Ke_Tiep(ByVal so_ngay As Integer) As Integer
Dim n As Integer = 1
While ((n Mod 4 = 0 And so_ngay > 366) Or (n Mod 4 <> 0 And so_ngay > 365))
If (n Mod 4 = 0) Then
so_ngay = so_ngay - 366
Else
so_ngay = so_ngay - 365
End If
n = n + 1
End While
Dim A() As Integer = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim B() As Integer = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim i As Integer = 1
While (so_ngay > A(i) Or so_ngay > B(i))
If (n Mod 4 = 0) Then
so_ngay = so_ngay - B(i)
Else
so_ngay = so_ngay - A(i)
End If
i = i + 1
End While

If (i Mod 4 = 0) Then
If (so_ngay + 1 > B(i)) Then
so_ngay = 1
Else
so_ngay = so_ngay + 1
End If
Else
If (so_ngay + 1 > A(i)) Then
so_ngay = 1
Else
so_ngay = so_ngay + 1
End If
End If
Return so_ngay
End Function

'bài 602: tìm ngày hôm qua
Function Tim_Ngay_Hom_Qua(ByVal so_ngay As Integer) As Integer
Dim n As Integer = 1
While ((n Mod 4 = 0 And so_ngay > 366) Or (n Mod 4 <> 0 And so_ngay > 365))
If (n Mod 4 = 0) Then
so_ngay = so_ngay - 366
Else
so_ngay = so_ngay - 365
End If
n = n + 1
End While
Dim A() As Integer = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim B() As Integer = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim i As Integer = 1
While (so_ngay > A(i) Or so_ngay > B(i))
If (n Mod 4 = 0) Then
so_ngay = so_ngay - B(i)
Else
so_ngay = so_ngay - A(i)
End If
i = i + 1
End While

If (i Mod 4 = 0) Then
If (so_ngay - 1 = 0) Then
so_ngay = B(i - 1)
Else
so_ngay = so_ngay - 1
End If
Else
If (so_ngay - 1 = 0) Then
so_ngay = A(i - 1)
Else
so_ngay = so_ngay - 1
End If
End If
Return so_ngay
End Function
'bài 603: tìm ngày kế đó k ngày
Function Tim_Ngay_Ke_K_Ngay(ByVal so_ngay As Integer, ByVal k As Integer) As Integer
Dim n As Integer = 1
While ((n Mod 4 = 0 And so_ngay > 366) Or (n Mod 4 <> 0 And so_ngay > 365))
If (n Mod 4 = 0) Then
so_ngay = so_ngay - 366
Else
so_ngay = so_ngay - 365
End If
n = n + 1
End While
Dim A() As Integer = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim B() As Integer = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim i As Integer = 1
While (so_ngay > A(i) Or so_ngay > B(i))
If (n Mod 4 = 0) Then
so_ngay = so_ngay - B(i)
Else
so_ngay = so_ngay - A(i)
End If
i = i + 1
End While

If (i Mod 4 = 0) Then
If (so_ngay + k > B(i)) Then
so_ngay = k - (B(i) - so_ngay)
Else
so_ngay = so_ngay + k
End If
Else
If (so_ngay + k > A(i)) Then
so_ngay = k - (A(i) - so_ngay)
Else
so_ngay = so_ngay + k
End If
End If
Return so_ngay
End Function
'bài 604: tìm ngày trước đó k ngày
Function Tim_Ngay_Truoc_K_Ngay(ByVal so_ngay As Integer, ByVal k As Integer) As Integer
Dim n As Integer = 1
While ((n Mod 4 = 0 And so_ngay > 366) Or (n Mod 4 <> 0 And so_ngay > 365))
If (n Mod 4 = 0) Then
so_ngay = so_ngay - 366
Else
so_ngay = so_ngay - 365
End If
n = n + 1
End While
Dim A() As Integer = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim B() As Integer = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim i As Integer = 1
While (so_ngay > A(i) Or so_ngay > B(i))
If (n Mod 4 = 0) Then
so_ngay = so_ngay - B(i)
Else
so_ngay = so_ngay - A(i)
End If
i = i + 1
End While

If (i Mod 4 = 0) Then
If (so_ngay - k < 0) Then
k = k - so_ngay
While (B(i - 1) - k < 0)
k = k - B(i - 1)
i = i - 1
End While
so_ngay = B(i - 1) - k
Else
so_ngay = so_ngay - k
End If
Else
If (so_ngay - k < 0) Then
k = k - so_ngay
While (A(i - 1) - k < 0)
k = k - A(i - 1)
i = i - 1
End While
so_ngay = A(i - 1) - k

Else
so_ngay = so_ngay - k
End If
End If

Return so_ngay
End Function
'bài 605: khoảng cách giữa hai ngày
Function Tinh_Khoang_Cach_Hai_Ngay(ByVal A As Ngay_Thang, ByVal B As Ngay_Thang) As Integer
Dim t() As Integer = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim n() As Integer = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim Khoang_Cach As Integer
If (A.Nam = B.Nam) Then
If (A.Nam Mod 4 = 0) Then
If (A.Thang = B.Thang) Then
Khoang_Cach = Math.Abs(A.Ngay - B.Ngay)
Else
Dim i As Integer
If (A.Thang < B.Thang) Then
i = A.Thang + 1
Khoang_Cach = n(A.Thang) - A.Ngay
While (i < B.Thang)
Khoang_Cach = Khoang_Cach + n(i)
i = i + 1
End While
Khoang_Cach = Khoang_Cach + B.Ngay
Else
i = B.Thang + 1
Khoang_Cach = n(B.Thang) - B.Ngay
While (i < A.Thang)
Khoang_Cach = Khoang_Cach + n(i)
i = i + 1
End While
Khoang_Cach = Khoang_Cach + A.Ngay
End If
End If
Else
If (A.Thang = B.Thang) Then
Khoang_Cach = Math.Abs(A.Ngay - B.Ngay)
Else
Dim i As Integer
If (A.Thang < B.Thang) Then
i = A.Thang + 1
Khoang_Cach = t(A.Thang) - A.Ngay
While (i < B.Thang)
Khoang_Cach = Khoang_Cach + t(i)
i = i + 1
End While
Khoang_Cach = Khoang_Cach + B.Ngay
Else
i = B.Thang + 1
Khoang_Cach = t(B.Thang) - B.Ngay
While (i < A.Thang)
Khoang_Cach = Khoang_Cach + t(i)
i = i + 1
End While
Khoang_Cach = Khoang_Cach + A.Ngay
End If
End If

End If
ElseIf (A.Nam < B.Nam) Then
Dim k As Integer = A.Nam + 1
Khoang_Cach = Tinh_So_Thu_Tu_Ngay_Trong_Nam(A.Ngay, A.Thang)
While (k < B.Nam)
If (k Mod 4 = 0) Then
Khoang_Cach = Khoang_Cach + 366
Else
Khoang_Cach = Khoang_Cach + 365
End If
k = k + 1
End While
Khoang_Cach = Khoang_Cach + Tinh_So_Thu_Tu_Ngay_Trong_Nam(B.Ngay, B.Thang)
Else
Dim k As Integer = B.Nam + 1
Khoang_Cach = Tinh_So_Thu_Tu_Ngay_Trong_Nam(B.Ngay, B.Thang)
While (k < A.Nam)
If (k Mod 4 = 0) Then
Khoang_Cach = Khoang_Cach + 366
Else
Khoang_Cach = Khoang_Cach + 365
End If
k = k + 1
End While
Khoang_Cach = Khoang_Cach + Tinh_So_Thu_Tu_Ngay_Trong_Nam(A.Ngay, A.Thang)
End If
Return Khoang_Cach
End Function
'bài 606: so sánh 2 ngày
Function So_Sanh_Hai_Ngay(ByVal A As Ngay_Thang, ByVal B As Ngay_Thang) As Integer
If (A.Nam < B.Nam) Then
Return 1
ElseIf (A.Nam > B.Nam) Then
Return -1
Else
Dim sna As Integer = Tinh_So_Thu_Tu_Ngay_Trong_Nam(A.Ngay, A.Thang)
Dim snb As Integer = Tinh_So_Thu_Tu_Ngay_Trong_Nam(B.Ngay, B.Thang)
If (sna < snb) Then
Return 1
ElseIf (sna > snb) Then
Return -1
Else
Return 0
End If
End If
End Function
TranNgocSang
TranNgocSang

Nam
Tổng số bài gửi : 17
Age : 34
Registration date : 11/05/2009

Về Đầu Trang Go down

Về Đầu Trang

- Similar topics

 
Permissions in this forum:
Bạn không có quyền trả lời bài viết