上集中只是顯示星期幾,不夠全面,完善後如下:
1、創建lbl1、lbl2、lbl3、txt1、cmd1、Timer1
2、lbl:“輸入年月日(如2000-8-16):”,設置lbl、txt1、cmd1的字體大小和顏色。Timer1的Enable屬性設爲False,Interval屬性設爲:1000。
3、雙擊cmd1,進入代碼編輯窗口,敲入:
Private Sub Timer1_Timer()
Dim c As Date
c = Time
lbl3.Caption = CStr(c)
End Sub
——————————————————
Private Sub cmd_Click()
If txt1.Text = "" Then
MsgBox "請輸入年月日!", , "錯誤!"
lbl2.Caption = ""
Exit Sub
End If
Timer1.Enabled = True
Dim a, b
b = Val(txt1.Text)
a = Weekday(b)
Select Case a
Case 1
lbl2.Caption = "星期日"
Case 2
lbl2.Caption = "星期一"
Case 3
lbl2.Caption = "星期二"
Case 4
lbl2.Caption = "星期三"
Case 5
lbl2.Caption = "星期四"
Case 6
lbl2.Caption = "星期五"
Case 7
lbl2.Caption = "星期六"
End Select
End Sub
實現效果如下:
界面效果:
不輸入年月日,則出現msgbox:
輸入正確格式的年月日:
顯示效果如下:
輸入錯誤字符,點擊cmd1沒反應。