Visual_Basic 板


LINE

請輸入專案類型(網站專案或者應用程式專案): 日出日落計算式 可以幫我檢查一下嗎? Public Sub SunRiseSet(Lat As Double, Lon As Double) Dim A(2), D(2) Dim Day, Month, Year, ZuluOffSet As Double Dim T, T0, TT, S, L0, L, G, F, U, V, W, A5, D5, R5, DR, K1, b As Double Dim V0, V1, V2 As Double Dim j, J3 As Integer Dim RiseSet As Boolean: RiseSet = True 'Sunrise Dim SunSet As String: SunSet = "Sunset at " Dim SunRise As String: SunRise = "Sunrise at " Dim M1 As String: M1 = "No sunrise this date" Dim M2 As String: M2 = "No sunset this date" Dim M3 As String: M3 = "Sun down all day" Dim M4 As String: M4 = "Sun up all day" P2 = 2 * PI DR = PI / 180 K1 = 15 * DR * 1.0027379 Day = CDbl(Format(Now, "dd")) Month = CDbl(Format(Now, "mm")) Year = CDbl(Format(Now, "yyyy")) '*************************************************** '****Get Time Zone off computer regional setting**** '*************************************************** 'Call GetLocalTZ function ZuluOffSet = CDbl(GetLocalTZ()) * -1 'Call Daylight Function DST = Daylight() 'YOU CAN RECONFIGURE THESE STATEMENTS TO WORK ANYWHERE. 'IT JUST TACKS ON THE TIME ZONE ABBREVIATION TO THE SUNRISE/SET If ZuluOffSet = 0 Then Zone = "UTC" End If If ZuluOffSet = 3 Then If DST = 0 Then Zone = "ADT" Else: Zone = "AST" End If End If If ZuluOffSet = 4 Then If DST = 0 Then Zone = "AST" Else: Zone = "EDT" End If End If If ZuluOffSet = 5 Then If DST = 0 Then Zone = "EST" Else: Zone = "CDT" End If End If If ZuluOffSet = 6 Then If DST = 0 Then Zone = "CST" Else: Zone = "MDT" End If End If If ZuluOffSet = 7 Then If DST = 0 Then Zone = "MST" Else: Zone = "PDT" End If End If If ZuluOffSet = 8 Then If DST = 0 Then Zone = "PST" Else: Zone = "ADT" End If End If If ZuluOffSet = 9 Then If DST = 0 Then Zone = "AST" Else: Zone = "HDT" End If End If If ZuluOffSet > 9 Then If DST = 0 Then Zone = "HST" Else: Zone = "You Have Problems" End If End If If ZuluOffSet < 0 Then MsgBox "According to your computer's regional settings, this program will not work. This program is for persons in North America Only. ", , "Program Error" End If Lon = Lon / 360 ZuluOffSet = ZuluOffSet / 24 'Get Year, Month, Day from System Clock G = 1 F = Day - Int(Day) - 0.5 j = -Int(7 * (Int((Month + 9) / 12) + Year) / 4) S = Sgn(Month - 9) J3 = Int(Year + S * Int(Abs(Month - 9) / 7)) J3 = -Int((Int(J3 / 100) + 1) * 3 / 4) j = j + Int(275 * Month / 9) + Int(Day) + G * J3 j = j + 1721027 + 2 + (367 * Year) If F < 0 Then F = F + 1 j = j - 1 End If T = (j - 2451545) + F TT = T / 36525 + 1 T0 = T / 36525 S = 24110.5 + 8640184.813 * T0 S = S + 86636.6 * ZuluOffSet + 86400 * Lon S = S / 86400 S = S - Int(S) T0 = S * 360 * DR T = T + ZuluOffSet L = 0.779072 + 0.00273790931 * T G = 0.993126 + 0.0027377785 * T L = L - Int(L) G = G - Int(G) L = L * P2 G = G * P2 V = 0.39785 * Sin(L) V = V - 0.01 * Sin(L - G) V = V + 0.00333 * Sin(L + G) V = V - 0.00021 * TT * Sin(L) U = 1 - 0.03349 * Cos(G) U = U - 0.00014 * Cos(2 * L) U = U + 0.00008 * Cos(L) W = -0.0001 - 0.04129 * Sin(2 * L) W = W + 0.03211 * Sin(G) W = W + 0.00104 * Sin(2 * L - G) W = W - 0.00035 * Sin(2 * L + G) W = W - 0.00008 * TT * Sin(G) S = W / Sqr(U - V * V) A5 = L + Atn(S / Sqr(1 - S * S)) S = V / Sqr(U) D5 = Atn(S / Sqr(1 - S * S)) R5 = 1.00021 * Sqr(U) A(1) = A5 D(1) = D5 T = T + 1 L = 0.779072 + 0.00273790931 * T G = 0.993126 + 0.0027377785 * T L = L - Int(L) G = G - Int(G) L = L * P2 G = G * P2 V = 0.39785 * Sin(L) V = V - 0.01 * Sin(L - G) V = V + 0.00333 * Sin(L + G) V = V - 0.00021 * TT * Sin(L) U = 1 - 0.03349 * Cos(G) U = U - 0.00014 * Cos(2 * L) U = U + 0.00008 * Cos(L) W = -0.0001 - 0.04129 * Sin(2 * L) W = W + 0.03211 * Sin(G) W = W + 0.00104 * Sin(2 * L - G) W = W - 0.00035 * Sin(2 * L + G) W = W - 0.00008 * TT * Sin(G) S = W / Sqr(U - V * V) A5 = L + Atn(S / Sqr(1 - S * S)) S = V / Sqr(U) D5 = Atn(S / Sqr(1 - S * S)) R5 = 1.00021 * Sqr(U) A(2) = A5 D(2) = D5 If A(2) < A(1) Then A(2) = A(2) + P2 Z1 = DR * 90.833 S = Sin(Lat * DR): c = Cos(Lat * DR) z = Cos(Z1): M8 = 0: W8 = 0 A0 = A(1): D0 = D(1) DA = A(2) - A(1): DD = D(2) - D(1) For C0 = 0 To 23 p = (CO + 1) / 24 A2 = A(1) + p * DA: D2 = D(1) + p * DD L0 = T0 + C0 * K1: L2 = L0 + K1 H0 = L0 - A0: H2 = L2 - A2 H1 = (H2 + H0) / 2 D1 = (D2 + D0) / 2 If C0 <= 0 Then V0 = S * Sin(D0) + c * Cos(D0) * Cos(H0) - z End If V2 = S * Sin(D2) + c * Cos(D2) * Cos(H2) - z If Sgn(V0) <> Sgn(V2) Then V1 = S * Sin(D1) + c * Cos(D1) * Cos(H1) - z A9 = 2 * V2 - 4 * V1 + 2 * V0: b = 4 * V1 - 3 * V0 - V2 D9 = b * b - 4 * A9 * V0 If D9 >= 0 Then D9 = Sqr(D9) If V0 < 0 And V2 > 0 Then RiseSet = True If V0 < 0 And V2 > 0 Then M8 = 1 If V0 > 0 And V2 < 0 Then RiseSet = False If V0 > 0 And V2 < 0 Then W8 = 1 E = (-b + D9) / (2 * A9) If E > 1 Or E < 0 Then E = (-b - D9) / (2 * A9) T3 = C0 + E + 1 / 120 H3 = Int(T3): M3 = Int((T3 - H3) * 60) If ZuluOffSet <> 0 Then If H3 < 0 Then H3 = 12 + H3 AMPM = "PM" ElseIf H3 > 12 Then H3 = H3 - 12 AMPM = "PM" ElseIf H3 = 0 Then H3 = 12 AMPM = "AM" ElseIf H3 = 12 Then AMPM = "PM" Else: AMPM = "AM" End If ElseIf H3 < 10 Then H3 = "0" + CStr(H3) End If If M3 < 10 Then M3 = "0" + CStr(M3) End If If RiseSet = True Then txtSunrise.Text = " " + CStr(H3) + ":" + CStr(M3) + " " + AMPM + " " + Zone Else: txtSunset.Text = " " + CStr(H3) + ":" + CStr(M3) + " " + AMPM + " " + Zone End If End If End If A0 = A2: D0 = D2: V0 = V2 Next If M8 = 0 And W8 = 0 Then If V2 < 0 Then txtSunrise.Text = M3 If V2 > 0 Then txtSunset.Text = M4 ElseIf M8 = 0 Then txtSunrise.Text = M1 ElseIf W8 = 0 Then txtSunset.Text = M2 End If End Sub 'PUT THESE IN A MODULE 'System clock/Time zone stuff Type SYSTEMTIME ' 16 Bytes wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As Integer End Type Public Type TIME_ZONE_INFORMATION Bias As Long StandardName(31) As Integer StandardDate As SYSTEMTIME StandardBias As Long DaylightName(31) As Integer DaylightDate As SYSTEMTIME DaylightBias As Long End Type Public Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long Function GetLocalTZ(Optional ByRef strTZName As String) As Long Dim objTimeZone As TIME_ZONE_INFORMATION Dim lngResult As Long Dim i As Long lngResult = GetTimeZoneInformation&(objTimeZone) Select Case lngResult Case 0&, 1& 'use standard time 'GetLocalTZ = -(objTimeZone.Bias + objTimeZone.StandardBias) * 60 'into minutes GetLocalTZ = -(objTimeZone.Bias + objTimeZone.StandardBias) / 60 For i = 0 To 31 If objTimeZone.StandardName(i) = 0 Then Exit For strTZName = strTZName & Chr(objTimeZone.StandardName(i)) Next Case 2& 'use daylight savings time 'GetLocalTZ = -(objTimeZone.Bias + objTimeZone.DaylightBias) * 60 'into minutes GetLocalTZ = -(objTimeZone.Bias + objTimeZone.DaylightBias) / 60 For i = 0 To 31 If objTimeZone.DaylightName(i) = 0 Then Exit For strTZName = strTZName & Chr(objTimeZone.DaylightName(i)) Next End Select End Function Function Daylight(Optional ByRef strTZName As String) As Long Dim objTimeZone As TIME_ZONE_INFORMATION Dim lngResult As Long Dim i As Long lngResult = GetTimeZoneInformation&(objTimeZone) If lngResult = 2 Then Daylight = 1 Else: Daylight = 0 End If End --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.72.108.170
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Visual_Basic/M.1459442544.A.754.html
1F:→ gundan: 你要檢查什麼,直接丟這麼多code來沒人會想看的啦 04/06 14:54
2F:→ gundan: 要檢查,最好的方式就是把資料丟進去用用看就知道啦 04/06 14:54
3F:→ MOONRAKER: 不要再自己做輪子了 http://sunrise-sunset.org/api 04/06 18:10
4F:→ newkoks: 但是我寫的環境不能連網路 04/08 01:24
5F:→ newkoks: 所以.... 04/08 01:24







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:WOW站內搜尋

TOP