上集中只是显示星期几,不够全面,完善后如下:
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没反应。