返回列表 上一主題 發帖

怎麼才能在萬年曆上增加時間

回復 1# Jared


  
  1. Private Sub 萬年曆()
  2.     Dim OBtop As Integer, OBLeft As Integer, R As Integer, W As Integer, i As Date
  3.         R = Label1.Top + 30
  4.           ReDim F_OB(1 To Day(DateSerial(ComboBox1, ComboBox2.Value + 1, 0)))
  5.           For i = DateSerial(ComboBox1, ComboBox2, 1) To DateSerial(ComboBox1, ComboBox2.Value + 1, 0) '年月1日到31日
  6.         W = Weekday(i) '位置
  7.         'With包覆程式為天數運算
  8.         With Controls.Add("Forms.OptionButton.1", i) 'Controls為控制項;OptionButton為單選紐
  9.             .Visible = True
  10.             .ControlTipText = i
  11.             .Top = R '最上面那排
  12.             .Left = Controls("Label" & W).Left '第一行呈現位置
  13.             .Height = 15      '高度
  14.             .Width = 30       '寬度
  15.             .Caption = Day(i) '計算當月最後一天天數
  16.         End With
  17.         Set F_OB(Day(i)).OB = Controls(i & "") '& c  '單選紐會彈跳出訊息
  18.         If Weekday(i) = 7 And Month(i) = Month(i + 1) Then
  19.             R = R + 30 '當位置等於7,R就加30   '** 備註 要考慮到同月份至少還有一天 **
  20.         End If
  21.      Next
  22.        Me.Frame1.Top = R + 30             '調整 時間的位置
  23.        Me.Height = R + Frame1.Height + 60 '調整 表單的高度
  24. End Sub
複製代碼
  1. Option Explicit
  2. Public WithEvents OB As MSForms.OptionButton
  3. Private Sub OB_Click()
  4.     Dim h As String, m As String
  5.     With UserForm1
  6.         h = "00 時 "
  7.         m = "00 分 "
  8.         With .TextBox1
  9.             If Val(.Text) >= 0 And Val(.Text) <= 24 Then h = Format(Val(.Text), "00 時 ")
  10.         End With
  11.         With .TextBox2
  12.             If Val(.Text) >= 0 And Val(.Text) <= 60 Then m = Format(Val(.Text), "00 分")
  13.         End With
  14.         test.TextBox1.Value = OB.ControlTipText & " " & h & m
  15.         .Hide
  16.     End With
  17. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 3# Jared
另可使 OptionButton 不可用
  1. Option Explicit
  2. Public WithEvents OB As MSForms.OptionButton
  3. Public WithEvents Tx As MSForms.TextBox
  4. 'UserForm_Initialize 中設立 TextBox1,TextBox2
  5. Private Sub Tx_Change()
  6.     Dim Msg As Boolean, E As Control
  7.     With Tx
  8.         If IsNumeric(.Text) Then
  9.             If Tx.Name = "TextBox1" Then
  10.                 If Val(.Text) > 0 And Val(.Text) <= 24 Then Msg = True
  11.             ElseIf Tx.Name = "TextBox2" Then
  12.                 If Val(.Text) > 0 And Val(.Text) <= 60 Then Msg = True
  13.             End If
  14.         End If
  15.     End With
  16.     For Each E In Tx.Parent.Controls
  17.         If TypeName(E) = "OptionButton" Then E.Enabled = Msg
  18.     Next
  19. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 盡多少本份,就得多少本事。
返回列表 上一主題