查看單個文章
舊 2005-03-22, 03:13 PM   #1
cocoking
註冊會員
榮譽勳章
UID - 79625
在線等級: 級別:13 | 在線時長:235小時 | 升級還需:17小時級別:13 | 在線時長:235小時 | 升級還需:17小時級別:13 | 在線時長:235小時 | 升級還需:17小時
註冊日期: 2003-06-21
VIP期限: 2009-10
文章: 60
精華: 0
現金: 5588 金幣
資產: 10588 金幣
Question 會寫VB的大大請進來看一下

小弟想寫個「萬年曆」加上「備忘錄」的功能
在萬年曆的部分就卡住了(紅色字為偵錯部份)
如果取消Private Sub nYear_Change()就能執行,不過當年改變時日曆不會更新 月則會
不知道問題出來哪?(command1(0~41)為顯示日期的 command button,日後還要作備忘錄的功能)
請大大幫忙看一下(form跟textbox我就不po了,跟除錯沒有關係)


Private Sub Command2_Click() '按一下此鍵年減1
nYear.Text = nYear.Text - 1
End Sub

Private Sub Command3_Click() '按一下此鍵年加1
nYear.Text = nYear.Text + 1
End Sub

Private Sub Command4_Click() '按一下此鍵月減1如果月<1 則月=12且年減1
nMonth.Text = nMonth.Text - 1
If nMonth.Text < 1 Then
nMonth.Text = 12
nYear.Text = nYear.Text - 1
End If
End Sub

Private Sub Command5_Click() '按一下此鍵月加1如果月>12則月=1年加1
nMonth.Text = nMonth.Text + 1
If nMonth.Text > 12 Then
nMonth.Text = 1
nYear.Text = nYear.Text + 1
End If
End Sub

Function getMMdays(pnYear, pnMonth) '定義每月的總天數
Select Case pnMonth
Case 1, 3, 5, 7, 8, 10, 12
getMMdays = 31
Case 4, 6, 9, 11
getMMdays = 30
Case 2
If (pnYear Mod 4) = 0 Then
If (pnYear Mod 100) = 0 Then
If (pnYear Mod 400) = 0 Then
getMMdays = 29
Else
getMMdays = 28
End If
Else
getMMdays = 29
End If
Else
getMMdays = 28
End If
End Select
End Function

Function getWeekday(pnYear, pnMonth) '自定函數求每月的第一天星期為?
getWeekday = Weekday(DateSerial(pnYear, pnMonth, 1))
End Function

Private Sub Form_Load() '表格load
nYear.Text = Year(Now)
nMonth.Text = Month(Now)
nMdays = getMMdays(CInt(nYear.Text), CInt(nMonth.Text))
nWday = getWeekday(CInt(nYear.Text), CInt(nMonth.Text))
Call showMonth(nMdays, nWday)
End Sub
Function showMonth(pnMdays, pnWday) '定義函數顯示日曆
pnMdays = getMMdays(CInt(nYear.Text), CInt(nMonth.Text)) - 1
pnWday = getWeekday(CInt(nYear.Text), CInt(nMonth.Text))
For I = 0 To pnMdays
Command1(pnWday - 1 + I).Caption = I + 1
Next I
End Function
Private Sub nMonth_Change() '月份改變時更新日曆
If nMonth.Text = "" Then
nMonth.Text = Month(Now)
End If
For I = 0 To 41
Command1(I).Caption = ""
Next I
nMdays = getMMdays(CInt(nYear.Text), CInt(nMonth.Text))
nWday = getWeekday(CInt(nYear.Text), CInt(nMonth.Text))
Call showMonth(nMdays, nWday)
End Sub

Private Sub nYear_Change() '年份改變時更新日曆
If nYear.Text = "" Then
nYear.Text = Year(Now)
End If
For I = 0 To 41
Command1(I).Caption = ""
Next I
nMdays = getMMdays(CInt(nYear.Text), CInt(nMonth.Text))
nWday = getWeekday(CInt(nYear.Text), CInt(nMonth.Text))
Call showMonth(nMdays, nWday)
End Sub
cocoking 目前離線  
送花文章: 74, 收花文章: 1 篇, 收花: 1 次
回覆時引用此帖