各位大大們~請問一下!
如何用VB來做像電腦裡時顯示的日期?
就是像整張月曆一樣 會顯示星期幾是幾日的!
麻煩各位幫忙解答了!!><
2006-02-19 05:28:51 · 2 個解答 · 發問者 κimi〃Little Q 2 in 電腦與網際網路 ➔ 程式設計
'表單置1個PictureBox跟CommandButton
Private Sub Command1_Click()
Dim Y As Integer, M As Integer, D As Integer, I As Integer, F As Integer, W As Long, S As String
Do
Y = Val(InputBox("請輸入年份(西元)"))
If Y = 0 Then Exit Sub
Loop Until Y > 0
Do
M = Val(InputBox("請輸入月份"))
If M = 0 Then Exit Sub
Loop Until M > 0 And M < 13
D = Day(DateSerial(Y, M + 1, 0))
With Picture1
.FontName = "細明體": .AutoRedraw = True: .Cls: .ForeColor = vbBlack
Picture1.Print Y; "年"; M; "月"; Tab(1)
Picture1.Print " ";
For I = 1 To 7
.ForeColor = Chg(I)
Picture1.Print WeekdayName(I) & " ";
Next
Picture1.Print Tab(1): W = .TextWidth(" 星期一")
For I = 1 To D
S = I: F = Weekday(DateSerial(Y, M, I)): .ForeColor = Chg(F)
Do
S = " " & S
If I = 1 Then
If .TextWidth(S) >= (((F - 1) Mod 7) + 1) * W Then Exit Do
Else
If .TextWidth(S) >= W Then Exit Do
End If
Loop
Picture1.Print S;
If F = 7 Then Picture1.Print Tab(1)
Next
.AutoRedraw = False
End With
End Sub
Function Chg(N)
Chg = vbBlack
If N = 7 Then
Chg = vbGreen
ElseIf N = 1 Then
Chg = vbRed
End If
End Function
2006-02-18 14:32:27 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋
你可以用現成的Controls, 就不用自己那麼辛苦[專案]->[設定使用元件]->勾選[Microsoft Calendar Control]會方便很多
2006-02-19 14:22:43 · answer #2 · answered by Brian 5 · 0⤊ 0⤋