(祝)東京オリンピック!

(祝)北京オリンピック!

フォームのいろいろ

EXCELのC_Label、ACCESSと仕様が異なります



   

COPY

  1. '-------------------------------------------------------------------
  2. Private WithEvents myLabel As MSForms.Label
  3. Private myParent As C_ObjControl
  4. Private myIndex As Long
  5. '-------------------------------------------------------------------
  6. Private Sub Class_Terminate()
  7. Set myLabel = Nothing
  8. Set myParent = Nothing
  9. End Sub
  10. '--------------------------------------------------------------------
  11. Public Property Let Item(ByRef val As MSForms.Label)
  12. Set myLabel = val
  13. End Property
  14. '--------------------------------------------------------------------
  15. Public Property Get Item() As MSForms.Label
  16. Set Item = myLabel
  17. End Property
  18. '--------------------------------------------------------------------
  19. Public Property Let Parent(ByRef val As Object)
  20. Set myParent = val
  21. End Property
  22. '--------------------------------------------------------------------
  23. Public Property Let Index(ByVal val As Long)
  24. myIndex = val
  25. End Property
  26. '--------------------------------------------------------------------
  27. Public Property Get Index() As Long
  28. Index = myIndex
  29. End Property
  30. '--------------------------------------------------------------------
  31. Public Property Get Self() As Object
  32. Set Self = Me
  33. End Property
  34. '--------------------------------------------------------------------
  35. Private Sub myLabel_Click()
  36. Call myParent.onClick(myIndex)
  37. End Sub
  38. '--------------------------------------------------------------------
  39. Private Sub myLabel_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  40. Cancel = True
  41. Call myParent.onDblClick(myIndex)
  42. End Sub
  43. '--------------------------------------------------------------------
  44. Private Sub myLabel_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  45. Call myParent.onMouseMove(myIndex)
  46. End Sub

プリントプレビューをフォームに表示



   

COPY

  1. Option Explicit
  2. '*******************************************************************
  3. Private Type Posi
  4. Top As Double
  5. Left As Double
  6. End Type
  7.  
  8. Public Event Click(ByVal Index As Long)
  9. Public Event DblClick(ByVal Index As Long)
  10. Public Event MouseMove(ByVal Index As Long)
  11.  
  12. Private Obj() As C_Label
  13. Private DefPosi() As Posi
  14. Private myItems As Object
  15. Private myParent As Object
  16.  
  17. Private AllRows As Long
  18. Private AllColumns As Long
  19. Private AllTop As Double
  20. Private AllLeft As Double
  21. Private HIntv As Double
  22. Private VIntv As Double
  23. Private LabCount As Long
  24. Private Size As Long
  25. Private PHeight As Double
  26. Private PWidth As Double
  27. Private offrow As Double
  28. Private offcol As Double
  29. '*******************************************************************
  30.  
  31. Public Property Let Parent(ByRef val As Object)
  32. Set myParent = val
  33. End Property
  34. '--------------------------------------------------------------------
  35. Public Property Get Items() As Object
  36. Set Items = myItems
  37. End Property
  38. '--------------------------------------------------------------------
  39. Public Property Let Rows(ByVal val As Long)
  40. AllRows = val
  41. AllColumns = 0
  42. End Property
  43. '--------------------------------------------------------------------
  44. Public Property Let Columns(ByVal val As Long)
  45. AllColumns = val
  46. AllRows = 0
  47. End Property
  48. '--------------------------------------------------------------------
  49. Public Property Let Top(ByVal val As Double)
  50. AllTop = val
  51. End Property
  52. '--------------------------------------------------------------------
  53. Public Property Let Count(ByVal val As Double)
  54. LabCount = val
  55. End Property
  56. '--------------------------------------------------------------------
  57. Public Property Let Left(ByVal val As Double)
  58. AllLeft = val
  59. End Property
  60. '--------------------------------------------------------------------
  61. Public Property Let HoriIntv(ByVal val As Double)
  62. HIntv = val
  63. End Property
  64. '--------------------------------------------------------------------
  65. Public Property Let VertIntv(ByVal val As Double)
  66. VIntv = val
  67. End Property
  68. '--------------------------------------------------------------------
  69. Public Property Let Height(ByVal val As Double)
  70. PHeight = val
  71. End Property
  72. '--------------------------------------------------------------------
  73. Public Property Get Height() As Double
  74. Height = PHeight
  75. End Property
  76. '--------------------------------------------------------------------
  77. Public Property Let Width(ByVal val As Double)
  78. PWidth = val
  79. End Property
  80. '--------------------------------------------------------------------
  81. Public Property Get Width() As Double
  82. Width = PWidth
  83. End Property
  84. '--------------------------------------------------------------------
  85. Public Property Let FontSize(ByVal val As Long)
  86. Size = val
  87. End Property
  88. '--------------------------------------------------------------------
  89. Private Sub Class_Initialize()
  90. AllRows = 0
  91. AllColumns = 0
  92. AllTop = 0
  93. AllLeft = 0
  94. HIntv = 0
  95. VIntv = 0
  96. PHeight = 0
  97. PWidth = 0
  98. LabCount = 0
  99. Size = 10
  100. End Sub
  101. '--------------------------------------------------------------------
  102. Private Sub Class_Terminate()
  103. Dim I As Long
  104.  
  105. For I = 1 To UBound(Obj)
  106. Set Obj(I) = Nothing
  107. Next I
  108. Set myParent = Nothing
  109. Set myItems = Nothing
  110. End Sub
  111. '--------------------------------------------------------------------
  112. Public Sub onClick(ByVal Index As Long)
  113. RaiseEvent Click(Index)
  114. End Sub
  115. '--------------------------------------------------------------------
  116. Public Sub onDblClick(ByVal Index As Long)
  117. RaiseEvent DblClick(Index)
  118. End Sub
  119. '--------------------------------------------------------------------
  120. Public Sub onMouseMove(ByVal Index As Long)
  121. RaiseEvent MouseMove(Index)
  122. End Sub
  123. '--------------------------------------------------------------------
  124. Public Sub Init(ByRef Dic As Object)
  125. Dim Ctrl As Control
  126. Dim I As Long
  127. Dim Key As Variant
  128. If Dic.Count > 0 Then
  129. LabCount = Dic.Count
  130. End If
  131. If LabCount = 0 Then
  132. Exit Sub
  133. End If
  134. Set myItems = New Collection
  135. ReDim Obj(1 To Dic.Count)
  136. ReDim DefPosi(1 To Dic.Count)
  137.  
  138. With myParent
  139. I = 1
  140. '-----
  141. For Each Key In Dic.keys
  142. '-----コントロールの追加
  143. Set Ctrl = .Controls.Add("Forms.Label.1", Dic(Key))
  144. '-----コントロールの整形
  145. With Ctrl
  146. .Visible = True
  147. '.Enabled = False
  148. .Caption = Dic(Key)
  149. If AllRows > 0 Then
  150. .Top = AllTop + ((I - 1) Mod AllRows) * (PHeight + VIntv)
  151. .Left = AllLeft + ((I - 1) \ AllRows) * (PWidth + HIntv)
  152. End If
  153. If AllColumns > 0 Then
  154. .Top = AllTop + ((I - 1) \ AllColumns) * (PHeight + VIntv)
  155. .Left = AllLeft + ((I - 1) Mod AllColumns) * (PWidth + HIntv)
  156. End If
  157.  
  158. .Font.Size = Size
  159. .Height = PHeight
  160. .Width = PWidth
  161. .SpecialEffect = fmSpecialEffectRaised
  162.  
  163. DefPosi(I).Top = .Top
  164. DefPosi(I).Left = .Left
  165.  
  166. End With
  167.  
  168. '-----コントロールのイベントクラスの作成
  169. Set Obj(I) = New C_Label
  170. With Obj(I)
  171. .Item = Ctrl
  172. .Index = Key
  173. .Parent = Me
  174. End With
  175. myItems.Add Obj(I)
  176. I = I + 1
  177. Next Key
  178. End With
  179.  
  180. End Sub
  181.  
  182. '*******************************************************************
  183. Public Sub OffSet(ByVal offtop As Double, _
  184. ByVal offleft As Double)
  185. Dim I As Long
  186. For I = 1 To UBound(Obj)
  187. With Obj(I).Item
  188. .Top = DefPosi(I).Top + offtop
  189. .Left = DefPosi(I).Left + offleft
  190. End With
  191. Next I
  192.  
  193. End Sub

フォームの値をテーブルにセット



   

COPY

  1. Option Compare Database
  2.  
  3. Private Sub buクリア_Click()
  4. Call CtrlClear
  5. End Sub
  6.  
  7. Private Sub bu移動_Click()
  8.  
  9. Me.SUB1.SetFocus
  10. DoCmd.GoToRecord , , acNewRec
  11. Me.SUB1.Form.SelHeight = 1
  12. Call CtrlClear
  13. Me.ID.Value = "新規"
  14. End Sub
  15.  
  16. Private Sub bu検索_Click()
  17. Dim whereSQL As String
  18. For Each Ctrl In Me.Controls
  19. If TypeName(Ctrl) = "TextBox" Then
  20. If Ctrl.Value <> "" Then
  21. If whereSQL = "" Then
  22. whereSQL = " A.[" & Ctrl.Name & "] Like '*" & Ctrl & "*'"
  23. Else
  24. whereSQL = whereSQL & " AND A.[" & Ctrl.Name & "] Like '*" & Ctrl & "*'"
  25. End If
  26. End If
  27. End If
  28. Next Ctrl
  29.  
  30. Me.SUB1.Form.RecordSource = "SELECT * FROM 連絡先 AS A WHERE" & whereSQL & ";"
  31.  
  32. End Sub
  33.  
  34. Private Sub bu更新_Click()
  35. Dim tableSQL As String
  36. Dim valueSQL As String
  37. Dim mySQL As String
  38. Dim Ctrl As Access.Control
  39. Dim I As Long
  40.  
  41. If Nz(Me.ID, "") = "" Then
  42. Exit Sub
  43. End If
  44.  
  45. If Me.ID = "新規" Then
  46. Call ADDNEW
  47. Exit Sub
  48. '追加
  49. For Each Ctrl In Me.Controls
  50. If TypeName(Ctrl) = "TextBox" Then
  51. Select Case Ctrl.Name
  52. Case "ID", "添付ファイル"
  53. Case Else
  54. If tableSQL = "" Then
  55. tableSQL = Ctrl.Name
  56. valueSQL = "'" & Ctrl.Value & "'"
  57. Else
  58. tableSQL = tableSQL & ", " & Ctrl.Name
  59. valueSQL = valueSQL & ", '" & Ctrl.Value & "'"
  60. End If
  61. End Select
  62. End If
  63. Next Ctrl
  64.  
  65. mySQL = "INSERT INTO 連絡先(" & tableSQL & ") VALUES(" & valueSQL & ");"
  66. DoCmd.RunSQL mySQL
  67.  
  68. Me.SUB1.Requery
  69. Me.ID.Value = DMax("ID", "連絡先")
  70.  
  71. Else
  72. Call UPDATE
  73. Exit Sub
  74. '更新
  75. For Each Ctrl In Me.Controls
  76. If TypeName(Ctrl) = "TextBox" Then
  77. Select Case Ctrl.Name
  78. Case "ID", "添付ファイル"
  79. Case Else
  80. If tableSQL = "" Then
  81. tableSQL = Ctrl.Name & "='" & Ctrl.Value & "'"
  82. Else
  83. tableSQL = tableSQL & ", " & Ctrl.Name & "='" & Ctrl.Value & "'"
  84. End If
  85. End Select
  86. End If
  87. Next Ctrl
  88.  
  89. mySQL = "UPDATE 連絡先 SET " & tableSQL & "WHERE 連絡先.[ID]=" & Me.ID & ";"
  90. DoCmd.RunSQL mySQL
  91.  
  92. Me.SUB1.Requery
  93.  
  94. End If
  95.  
  96. End Sub
  97.  
  98. Private Sub bu閉じる_Click()
  99.  
  100. DoCmd.Close acForm, Me.Name, acSaveNo
  101.  
  102. End Sub
  103.  
  104. Private Sub Form_Load()
  105.  
  106. Me.SUB1.SourceObject = "検索SUB"
  107. Me.SUB1.Form.RecordSource = "SELECT * FROM 連絡先;"
  108.  
  109. End Sub
  110.  
  111. Private Sub CtrlClear()
  112. Dim Ctrl As Access.Control
  113.  
  114. For Each Ctrl In Me.Controls
  115. If TypeName(Ctrl) = "TextBox" Then
  116. Ctrl.Value = ""
  117. End If
  118. Next Ctrl
  119.  
  120. End Sub
  121.  
  122. Private Sub UPDATE()
  123. Dim CN As ADODB.Connection
  124. Dim RS As New ADODB.Recordset
  125. Dim Ctrl As Access.Control
  126.  
  127. Set CN = CurrentProject.Connection
  128.  
  129. RS.Open "連絡先", CN, adOpenKeyset, adLockOptimistic, adCmdTableDirect
  130. Let RS.Index = "Ind"
  131. RS.Seek Me.ID, adSeekFirstEQ
  132.  
  133. For Each Ctrl In Me.Controls
  134. Select Case TypeName(Ctrl)
  135. Case "TextBox"
  136. Select Case Ctrl.Name
  137. Case "ID"
  138. Case Else
  139. RS.Fields(Ctrl.Name) = Ctrl.Value
  140. End Select
  141. Case "Attachment"
  142. End If
  143. Next Ctrl
  144.  
  145. RS.UPDATE
  146.  
  147. RS.Close
  148. Set RS = Nothing
  149. CN.Close
  150. Set CN = Nothing
  151.  
  152. Me.SUB1.Requery
  153.  
  154. End Sub
  155.  
  156. Private Sub ADDNEW()
  157. Dim CN As ADODB.Connection
  158. Dim RS As New ADODB.Recordset
  159. Dim Ctrl As Access.Control
  160.  
  161. Set Con = CurrentProject.Connection
  162. Set Rst = New ADODB.Recordset
  163.  
  164. Rst.Open "連絡先", Con, adOpenForwardOnly, adLockPessimistic
  165.  
  166. With Rst
  167. .ADDNEW
  168.  
  169. For Each Ctrl In Me.Controls
  170. Select Case TypeName(Ctrl)
  171. Case "TextBox"
  172. Select Case Ctrl.Name
  173. Case "ID"
  174. Case Else
  175. RS.Fields(Ctrl.Name) = Ctrl.Value
  176. End Select
  177. Case "Attachment"
  178. End If
  179. Next Ctrl
  180.  
  181. .UPDATE
  182. End With
  183.  
  184. Rst.Close
  185. Set Rst = Nothing
  186. Set Con = Nothing
  187.  
  188. Me.SUB1.Requery
  189. Me.ID.Value = DMax("ID", "連絡先")
  190.  
  191. End Sub
  192.  
  193. Private Sub クリア2()
  194. Call ClearControls
  195. End Sub
  196.  
  197. Private Sub 閉じる2()
  198. DoCmd.Close acForm, "住所録", acSaveNo
  199. End Sub
  200.  
  201. Sub ClearControls()
  202. Dim Ctl As Control
  203.  
  204. For Each Ctl In Me.Controls
  205. If Ctl.ControlType = acTextBox Then
  206. Ctl = Null
  207. End If
  208. Next Ctl
  209. End Sub
  210. Private Sub cmd追加2()
  211. '[追加]ボタンクリック時
  212.  
  213. 'フォームのレコードセットの編集を開始
  214. Me.Recordset.Edit
  215.  
  216. '商品写真フィールドのレコードセットに対する操作
  217. With Me.Recordset!商品写真.Value
  218. .ADDNEW
  219. !FileData.LoadFromFile "c:\Picture\img17.jpg"
  220. .UPDATE
  221. .Close
  222. End With
  223.  
  224. '添付ファイルコントロールの表示を更新
  225. Me!商品写真.Requery
  226.  
  227. End Sub

サブフォームのセレクタをクリックして親フォームにレコードの値をセット



   

COPY

  1. Option Compare Database
  2.  
  3. Private Sub Form_Click()
  4. Dim Ctrl As Access.Control
  5.  
  6. If Me.SelHeight > 0 Then
  7. For Each Ctrl In Me.Controls
  8. Select Case TypeName(Ctrl)
  9. Case "TextBox"
  10. If Ctrl.Name = "ID" Then
  11. If Nz(Ctrl.Value, "") = "" Then
  12. 'Me.Parent.Controls(Ctrl.Name).Value = DMax(Ctrl.Name, "連絡先") + 1
  13. Me.Parent.Controls(Ctrl.Name).Value = "新規"
  14. Else
  15. Me.Parent.Controls(Ctrl.Name).Value = Ctrl.Value
  16. End If
  17. Else
  18. Me.Parent.Controls(Ctrl.Name).Value = Ctrl.Value
  19. End If
  20. End Select
  21. Next Ctrl
  22. End If
  23.  
  24. End Sub

Access カレンダーFORM



   

COPY

  1. '----------------------------------------------------------------
  2. 'カレンダー
  3. '令和3年5月6日
  4. '----------------------------------------------------------------
  5. Option Compare Database
  6. Option Explicit
  7.  
  8. Private WithEvents myControls As C_Controls
  9.  
  10. Private Const SHIFT_MASK As Long = 1
  11.  
  12. Private Const FirstYobi As Long = vbSunday
  13.  
  14. Private HoldDate As Long
  15. Private HoldYear As Long
  16. Private HoldMonth As Long
  17. Private HoldDay As Long
  18.  
  19. Private Enum IncType
  20. Forward = 1
  21. Backward = -1
  22. End Enum
  23.  
  24. Private GetYobi As C_KyuZitu
  25.  
  26. Private Const IntvDay As String = "d"
  27. Private Const IntvMonth As String = "m"
  28. Private Const IntvYear As String = "yyyy"
  29. Private Const IntvWeek As String = "ww"
  30.  
  31. Private CurYear As Long
  32. Private CurMonth As Long
  33. Private CurDay As Long
  34.  
  35. Private DaysAndWeeks() As Long
  36. Private Yobi As Variant
  37. Private SelectDay As String
  38.  
  39. Public Property Get DateNum() As Long
  40. If CurYear = 0 Then
  41. DateNum = 0
  42. Else
  43. DateNum = DateSerial(CurYear, CurMonth, CurDay)
  44. End If
  45. End Property
  46.  
  47. Public Property Get WeekNum() As Long
  48. GetYobi.SetNumDate = DateSerial(CurYear, CurMonth, CurDay)
  49. WeekNum = GetYobi.WeekNum
  50. End Property
  51. '----------------------------------------------------------------
  52. '
  53. Private Sub Form_Load()
  54.  
  55. Dim Ctrl As Access.Control
  56. Dim I As Long
  57.  
  58. If Nz(Me.OpenArgs, "") = "" Then
  59. HoldDate = Date
  60. Else
  61. If IsDate(Me.OpenArgs) Then
  62. HoldDate = DateSerial(DatePart("YYYY", Me.OpenArgs), _
  63. DatePart("m", Me.OpenArgs), _
  64. DatePart("d", Me.OpenArgs))
  65. Else
  66. HoldDate = Date
  67. End If
  68. End If
  69.  
  70. HoldYear = Year(HoldDate)
  71. HoldMonth = Month(HoldDate)
  72. HoldDay = Day(HoldDate)
  73.  
  74. Set GetYobi = New C_KyuZitu
  75. GetYobi.pYear = HoldYear
  76.  
  77. CurYear = HoldYear
  78. CurMonth = HoldMonth
  79. CurDay = HoldDay
  80.  
  81. Set myControls = New C_Controls
  82. With myControls
  83. Set .Parent = Me
  84. .Init
  85. End With
  86. Yobi = Array("日", "月", "火", "水", "木", "金", "土")
  87. For I = 0 To 6
  88. Me("Y" & I).Caption = Yobi((FirstYobi - 1 + I) Mod 7)
  89. Select Case I
  90. Case 0
  91. Me("Y" & I).ForeColor = vbRed
  92. Case 6
  93. Me("Y" & I).ForeColor = vbBlue
  94. End Select
  95. Next I
  96. Call SetCurDisp
  97. Call DispDraw
  98.  
  99. End Sub
  100. '----------------------------------------------------------------
  101. '
  102. Private Sub Form_Close()
  103.  
  104. End Sub
  105. '----------------------------------------------------------------
  106. '
  107. Private Sub SetCurDisp()
  108.  
  109. Me.DMONTH.Caption = CurMonth
  110. Me.DYEAR.Caption = CurYear
  111. End Sub
  112. '----------------------------------------------------------------
  113. '
  114. Private Sub DispDraw()
  115. Dim Ctrl As Access.Control
  116. Dim NewSelect As String
  117. Dim OneDayYobi As Long
  118. Dim OneDaySerial As Long
  119. Dim I As Long
  120.  
  121. GetYobi.pYear = CurYear
  122.  
  123. '選択月の最初の日のシリアル値
  124. OneDaySerial = DateSerial(CurYear, CurMonth, 1)
  125.  
  126. '選択月の最初の日の曜日
  127. OneDayYobi = Weekday(OneDaySerial, FirstYobi)
  128.  
  129. '配列にシリアル値をセット
  130. ReDim DaysAndWeeks(0 To 41)
  131. For I = 0 To UBound(DaysAndWeeks)
  132. DaysAndWeeks(I) = OneDaySerial - (OneDayYobi - 1) + I
  133. Next I
  134.  
  135. 'ラベルのキャプションに日にちをセット
  136. For I = 0 To UBound(DaysAndWeeks)
  137. Me("Day" & I).Caption = Day(DaysAndWeeks(I))
  138.  
  139. If Me.DMONTH.Caption <> Month(DaysAndWeeks(I)) Then
  140. Me("Day" & I).FontSize = 10
  141. Else
  142. Me("Day" & I).FontSize = 12
  143. End If
  144.  
  145. If Me("Day" & I).ForeColor <> InteriorColor(DaysAndWeeks(I)) Then
  146. Me("Day" & I).ForeColor = InteriorColor(DaysAndWeeks(I))
  147. End If
  148.  
  149. If DaysAndWeeks(I) = DateSerial(CurYear, CurMonth, CurDay) Then
  150. NewSelect = "Day" & I
  151. End If
  152. Next I
  153.  
  154. Call EffectDraw(NewSelect)
  155.  
  156. End Sub
  157. '----------------------------------------------------------------
  158. '
  159. Private Sub EffectDraw(NewSelect As String)
  160.  
  161. If Len(SelectDay) > 0 Then
  162. If SelectDay <> NewSelect Then
  163. Me(SelectDay).SpecialEffect = acNormal
  164. End If
  165. End If
  166.  
  167. SelectDay = NewSelect
  168. Me(SelectDay).SpecialEffect = acEffectSunken
  169.  
  170. Me.Repaint
  171.  
  172. End Sub
  173. '----------------------------------------------------------------
  174. '
  175. Private Function InteriorColor(DrawDate As Long) As Long
  176.  
  177. GetYobi.SetNumDate = DrawDate
  178.  
  179. Select Case GetYobi.WeekNum
  180. Case 1, 10, 11, 12, 13
  181. InteriorColor = vbRed
  182. Case 7
  183. InteriorColor = vbBlue
  184. Case Else
  185. InteriorColor = vbBlack
  186. End Select
  187.  
  188. End Function
  189. '----------------------------------------------------------------
  190. '
  191. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  192.  
  193. Call ShiftKeys(KeyCode, Shift)
  194.  
  195. End Sub
  196. '----------------------------------------------------------------
  197. '
  198. Private Sub myControls_Click(myCont As Object)
  199.  
  200. Select Case myCont.Name
  201. Case "NM"
  202. Me.buDummy.SetFocus
  203. Call NextMonth
  204. Case "NY"
  205. Me.buDummy.SetFocus
  206. Call NextYear
  207. Case "PM"
  208. Me.buDummy.SetFocus
  209. Call PreviousMonth
  210. Case "PY"
  211. Me.buDummy.SetFocus
  212. Call PreviousYear
  213. Case "bu閉じる"
  214. Me.buDummy.SetFocus
  215. Call CloseForm(False)
  216. Case "bu初期"
  217. Me.buDummy.SetFocus
  218. CurYear = HoldYear
  219. CurMonth = HoldMonth
  220. CurDay = HoldDay
  221. Call SetCurDisp
  222. Call DispDraw
  223. Case "bu削除"
  224. Me.buDummy.SetFocus
  225. CurYear = 0
  226. Call CloseForm(True)
  227. Case Else
  228. Select Case True
  229. Case InStr(myCont.Name, "Day") = 1
  230. If myCont.SpecialEffect = acEffectSunken Then
  231. Call CloseForm(True)
  232. Else
  233. If CurMonth <> Month(DaysAndWeeks(Mid(myCont.Name, Len("Day") + 1))) Then
  234. Call ClickDate(myCont.Name)
  235. Call SetCurDisp
  236. Call DispDraw
  237. Else
  238. Call EffectDraw(myCont.Name)
  239. Call ClickDate(myCont.Name)
  240. End If
  241. End If
  242. End Select
  243. End Select
  244.  
  245. End Sub
  246. '----------------------------------------------------------------
  247. '
  248. Private Sub myControls_DblClick(myCont As Object, Cancel As Integer)
  249.  
  250. Select Case True
  251. Case InStr(myCont.Name, "Day") = 1
  252. Call EffectDraw(myCont.Name)
  253. Call ClickDate(myCont.Name)
  254. Call CloseForm(True)
  255. End Select
  256.  
  257. End Sub
  258. '----------------------------------------------------------------
  259. '
  260. Private Sub myControls_KeyDown(myCont As Object, KeyCode As Integer, Shift As Integer)
  261.  
  262. Select Case myCont.Name
  263. Case "PM", "NM", "PY", "NY", "bu閉じる", "bu初期", "bu削除"
  264. Call ShiftKeys(KeyCode, Shift)
  265. Case Else
  266. Select Case True
  267. Case InStr(myCont.Name, "Day") = 1
  268. Call ShiftKeys(KeyCode, Shift)
  269. End Select
  270. End Select
  271.  
  272. End Sub
  273. '----------------------------------------------------------------
  274. '
  275. Private Sub ShiftKeys(KeyCode As Integer, Shift As Integer)
  276. Dim ShiftDown As Boolean
  277.  
  278. ShiftDown = ((Shift And SHIFT_MASK) > 0)
  279.  
  280. Select Case KeyCode
  281. Case vbKeyEscape
  282. Call CloseForm(Hide:=False)
  283. Case vbKeyReturn
  284. Call CloseForm(Hide:=True)
  285. Case vbKeyHome
  286. If ShiftDown Then
  287. Call MoveToToday(False)
  288. Else
  289. Call MoveToToday(True)
  290. End If
  291. Case vbKeyPageUp
  292. If ShiftDown Then
  293. Call PreviousYear
  294. Else
  295. Call PreviousMonth
  296. End If
  297. Case vbKeyPageDown
  298. If ShiftDown Then
  299. Call NextYear
  300. Else
  301. Call NextMonth
  302. End If
  303. Case vbKeyRight
  304. If ShiftDown Then
  305. Call NextYear
  306. Else
  307. Call NextDay
  308. End If
  309. Case vbKeyLeft
  310. If ShiftDown Then
  311. Call PreviousYear
  312. Else
  313. Call PreviousDay
  314. End If
  315. Case vbKeyUp
  316. If ShiftDown Then
  317. Call PreviousMonth
  318. Else
  319. Call PreviousWeek
  320. End If
  321. Case vbKeyDown
  322. If ShiftDown Then
  323. Call NextMonth
  324. Else
  325. Call NextWeek
  326. End If
  327. End Select
  328.  
  329. KeyCode = 0
  330. End Sub
  331. '----------------------------------------------------------------
  332. '
  333. Public Sub Today()
  334. Call MoveToToday(UseCurYear:=True)
  335. End Sub
  336. '----------------------------------------------------------------
  337. '
  338. Public Sub NextDay()
  339. Call ChangeDate(IntvDay, IncType.Forward)
  340. End Sub
  341. '----------------------------------------------------------------
  342. '
  343. Public Sub NextMonth()
  344. Call ChangeDate(IntvMonth, IncType.Forward)
  345. End Sub
  346. '----------------------------------------------------------------
  347. '
  348. Public Sub NextYear()
  349. Call ChangeDate(IntvYear, IncType.Forward)
  350. End Sub
  351. '----------------------------------------------------------------
  352. '
  353. Public Sub NextWeek()
  354. Call ChangeDate(IntvWeek, IncType.Forward)
  355. End Sub
  356. '----------------------------------------------------------------
  357. '
  358. Public Sub PreviousDay()
  359. Call ChangeDate(IntvDay, IncType.Backward)
  360. End Sub
  361. '----------------------------------------------------------------
  362. '
  363. Public Sub PreviousMonth()
  364. Call ChangeDate(IntvMonth, IncType.Backward)
  365. End Sub
  366. '----------------------------------------------------------------
  367. '
  368. Public Sub PreviousYear()
  369. Call ChangeDate(IntvYear, IncType.Backward)
  370. End Sub
  371. '----------------------------------------------------------------
  372. '
  373. Public Sub PreviousWeek()
  374. Call ChangeDate(IntvWeek, IncType.Backward)
  375. End Sub
  376. '----------------------------------------------------------------
  377. '
  378. Private Sub MoveToToday(UseCurYear As Boolean)
  379.  
  380. If UseCurYear Then
  381. CurYear = HoldYear
  382. End If
  383. CurMonth = HoldMonth
  384. CurDay = HoldDay
  385.  
  386. Call SetCurDisp
  387. Call DispDraw
  388. End Sub
  389. '----------------------------------------------------------------
  390. '
  391. Private Sub ChangeDate(IntvStr As String, IT As IncType)
  392. Dim bufMonth As Integer
  393. Dim bufYear As Integer
  394. Dim bufDay As Integer
  395. Dim NewSelect As String
  396. Dim OLDDate As Long
  397. Dim NewDate As Long
  398. Dim Inc As Long
  399. Dim I As Long
  400.  
  401. If IT = Forward Then
  402. Inc = 1
  403. Else
  404. Inc = -1
  405. End If
  406. OLDDate = DateSerial(CurYear, CurMonth, CurDay)
  407. NewDate = DateAdd(IntvStr, Inc, OLDDate)
  408.  
  409. bufMonth = DatePart(IntvMonth, NewDate)
  410. bufYear = DatePart(IntvYear, NewDate)
  411. bufDay = DatePart(IntvDay, NewDate)
  412.  
  413. If CurMonth = bufMonth And _
  414. CurYear = bufYear Then
  415. CurDay = bufDay
  416. For I = 0 To UBound(DaysAndWeeks)
  417. If DaysAndWeeks(I) = DateSerial(CurYear, CurMonth, CurDay) Then
  418. NewSelect = "Day" & I
  419. End If
  420. Next I
  421. Call EffectDraw(NewSelect)
  422. Else
  423. CurDay = bufDay
  424. CurMonth = bufMonth
  425. CurYear = bufYear
  426.  
  427. Call SetCurDisp
  428. Call DispDraw
  429. End If
  430. End Sub
  431. '----------------------------------------------------------------
  432. '
  433. Private Sub CloseForm(Hide As Boolean)
  434.  
  435. If ThisFormSub() Then
  436. Exit Sub
  437. End If
  438. If Hide Then
  439. Me.Visible = False
  440. Else
  441. DoCmd.CLOSE acForm, Me.Name, acSaveNo
  442. End If
  443.  
  444. End Sub
  445. '----------------------------------------------------------------
  446. '
  447. Private Function ThisFormSub() As Boolean
  448. Dim strName As String
  449. On Error Resume Next
  450.  
  451. strName = Me.Parent.Name
  452. ThisFormSub = (Err.Number = 0)
  453. Err.Clear
  454. End Function
  455. '----------------------------------------------------------------
  456. '
  457. Private Sub ClickDate(ClickName As String)
  458. Dim Num As Long
  459.  
  460. Num = Mid(ClickName, Len("Day") + 1)
  461. CurYear = Year(DaysAndWeeks(Num))
  462. CurMonth = Month(DaysAndWeeks(Num))
  463. CurDay = Day(DaysAndWeeks(Num))
  464.  
  465. End Sub

C_Button



   

COPY

  1. Option Explicit
  2. '-------------------------------------------------------------------
  3.  
  4. Private WithEvents myButton As Access.CommandButton
  5. Private myParent As C_Controls
  6. Private myIndex As Long'--------------------------------------------------------------------
  7. '
  8. Public Property Set Item(ByRef Obj As Access.CommandButton)
  9.  
  10. Set myButton = Obj
  11.  
  12. End Property'--------------------------------------------------------------------
  13. '
  14. Public Property Get Item() As Access.CommandButton
  15.  
  16. Set Item = myButton
  17.  
  18. End Property'--------------------------------------------------------------------
  19. '
  20. Public Property Set Parent(ByRef Obj As C_Controls)
  21.  
  22. Set myParent = Obj
  23.  
  24. End Property'--------------------------------------------------------------------
  25. '
  26. Public Property Let Index(ByVal val As Long)
  27.  
  28. myIndex = val
  29.  
  30. End Property'--------------------------------------------------------------------
  31. '
  32. Public Property Get Index() As Long
  33.  
  34. Index = myIndex
  35.  
  36. End Property'--------------------------------------------------------------------
  37. '
  38. Public Property Get Self() As Object
  39.  
  40. Set Self = Me
  41.  
  42. End Property'--------------------------------------------------------------------
  43. '
  44. Public Sub DEL()
  45.  
  46. Set myButton = Nothing
  47. Set myParent = Nothing
  48.  
  49. End Sub'--------------------------------------------------------------------
  50. '
  51. Private Sub Class_Terminate()
  52.  
  53. Set myButton = Nothing
  54. Set myParent = Nothing
  55.  
  56. End Sub'--------------------------------------------------------------------
  57. '
  58. Private Sub myButton_Click()
  59.  
  60. Call myParent.onClick(myButton)
  61.  
  62. End Sub'--------------------------------------------------------------------
  63. '
  64. Private Sub myButton_DblClick(Cancel As Integer)
  65.  
  66. Call myParent.onDblClick(myButton, Cancel)
  67.  
  68. End Sub'--------------------------------------------------------------------
  69. '
  70. Private Sub myButton_KeyDown(KeyCode As Integer, Shift As Integer)
  71.  
  72. Call myParent.onKeyDown(myButton, KeyCode, Shift)
  73.  
  74. End Sub'--------------------------------------------------------------------
  75. '
  76. Private Sub myButton_MouseMove(Button As Integer, _
  77. Shift As Integer, _
  78. X As Single, _
  79. Y As Single)
  80.  
  81. Call myParent.onMouseMove(myButton, Button, Shift, X, Y)
  82.  
  83. End Sub

C_CheckBox



   

COPY

  1. Option Explicit
  2. '-------------------------------------------------------------------
  3.  
  4. Private WithEvents myCheckBox As Access.CheckBox
  5. Private myParent As C_Controls
  6. Private myIndex As Long'--------------------------------------------------------------------
  7. '
  8. Public Property Set Item(ByRef Obj As Access.CheckBox)
  9.  
  10. Set myCheckBox = Obj
  11.  
  12. End Property'--------------------------------------------------------------------
  13. '
  14. Public Property Get Item() As Access.CheckBox
  15.  
  16. Set Item = myCheckBox
  17.  
  18. End Property'--------------------------------------------------------------------
  19. '
  20. Public Property Set Parent(ByRef Obj As C_Controls)
  21.  
  22. Set myParent = Obj
  23.  
  24. End Property'--------------------------------------------------------------------
  25. '
  26. Public Property Let Index(ByVal val As Long)
  27.  
  28. myIndex = val
  29.  
  30. End Property'--------------------------------------------------------------------
  31. '
  32. Public Property Get Index() As Long
  33.  
  34. Index = myIndex
  35.  
  36. End Property'--------------------------------------------------------------------
  37. '
  38. Public Property Get Self() As Object
  39.  
  40. Set Self = Me
  41.  
  42. End Property'--------------------------------------------------------------------
  43. '
  44. Public Sub DEL()
  45.  
  46. Set myCheckBox = Nothing
  47. Set myParent = Nothing
  48.  
  49. End Sub'--------------------------------------------------------------------
  50. '
  51. Private Sub Class_Terminate()
  52.  
  53. Set myCheckBox = Nothing
  54. Set myParent = Nothing
  55.  
  56. End Sub'--------------------------------------------------------------------
  57. '
  58. Private Sub myCheckBox_Click()
  59.  
  60. Call myParent.onClick(myCheckBox)
  61.  
  62. End Sub'--------------------------------------------------------------------
  63. '
  64. Private Sub myCheckBox_DblClick(Cancel As Integer)
  65.  
  66. Call myParent.onDblClick(myCheckBox, Cancel)
  67.  
  68. End Sub'--------------------------------------------------------------------
  69. '
  70. Private Sub myCheckBox_MouseMove(Button As Integer, _
  71. Shift As Integer, _
  72. X As Single, _
  73. Y As Single)
  74.  
  75. Call myParent.onMouseMove(myCheckBox, Button, Shift, X, Y)
  76.  
  77. End Sub

C_ComboBox



   

COPY

  1. Option Explicit
  2. '-------------------------------------------------------------------
  3.  
  4. Private WithEvents myCheckBox As Access.CheckBox
  5. Private myParent As C_Controls
  6. Private myIndex As Long'--------------------------------------------------------------------
  7. '
  8. Public Property Set Item(ByRef Obj As Access.CheckBox)
  9.  
  10. Set myCheckBox = Obj
  11.  
  12. End Property'--------------------------------------------------------------------
  13. '
  14. Public Property Get Item() As Access.CheckBox
  15.  
  16. Set Item = myCheckBox
  17.  
  18. End Property'--------------------------------------------------------------------
  19. '
  20. Public Property Set Parent(ByRef Obj As C_Controls)
  21.  
  22. Set myParent = Obj
  23.  
  24. End Property'--------------------------------------------------------------------
  25. '
  26. Public Property Let Index(ByVal val As Long)
  27.  
  28. myIndex = val
  29.  
  30. End Property'--------------------------------------------------------------------
  31. '
  32. Public Property Get Index() As Long
  33.  
  34. Index = myIndex
  35.  
  36. End Property'--------------------------------------------------------------------
  37. '
  38. Public Property Get Self() As Object
  39.  
  40. Set Self = Me
  41.  
  42. End Property'--------------------------------------------------------------------
  43. '
  44. Public Sub DEL()
  45.  
  46. Set myCheckBox = Nothing
  47. Set myParent = Nothing
  48.  
  49. End Sub'--------------------------------------------------------------------
  50. '
  51. Private Sub Class_Terminate()
  52.  
  53. Set myCheckBox = Nothing
  54. Set myParent = Nothing
  55.  
  56. End Sub'--------------------------------------------------------------------
  57. '
  58. Private Sub myCheckBox_Click()
  59.  
  60. Call myParent.onClick(myCheckBox)
  61.  
  62. End Sub'--------------------------------------------------------------------
  63. '
  64. Private Sub myCheckBox_DblClick(Cancel As Integer)
  65.  
  66. Call myParent.onDblClick(myCheckBox, Cancel)
  67.  
  68. End Sub'--------------------------------------------------------------------
  69. '
  70. Private Sub myCheckBox_MouseMove(Button As Integer, _
  71. Shift As Integer, _
  72. X As Single, _
  73. Y As Single)
  74.  
  75. Call myParent.onMouseMove(myCheckBox, Button, Shift, X, Y)
  76.  
  77. End Sub

C_Controls



   

COPY

  1. Option Explicit
  2. '*******************************************************************
  3. Public Event Click(myCont As Object)
  4. Public Event Change(myCont As Object)
  5. Public Event DblClick(myCont As Object, _
  6. Cancel As Integer)
  7. Public Event MouseMove(myCont As Object, _
  8. Button As Integer, _
  9. Shift As Integer, _
  10. X As Single, _
  11. Y As Single)
  12. Public Event KeyPress(myCont As Object, _
  13. KeyAscii As Integer)
  14. Public Event KeyDown(myCont As Object, _
  15. KeyCode As Integer, _
  16. Shift As Integer)
  17. Private Labels As Dictionary
  18. Private TextBoxs As Dictionary
  19. Private CheckBoxs As Dictionary
  20. Private ComboBoxs As Dictionary
  21. Private Buttons As Dictionary
  22.  
  23. Private myParent As Object
  24. '*******************************************************************
  25. '
  26. Public Property Set Parent(ByRef Obj As Object)
  27.  
  28. Set myParent = Obj
  29.  
  30. End Property
  31. '*******************************************************************
  32. '
  33. Public Sub onClick(myCont As Object)
  34.  
  35. RaiseEvent Click(myCont)
  36.  
  37. End Sub
  38. '*******************************************************************
  39. '
  40. Public Sub onDblClick(myCont As Object, Cancel As Integer)
  41.  
  42. RaiseEvent DblClick(myCont, Cancel)
  43.  
  44. End Sub
  45. '*******************************************************************
  46. '
  47. Public Sub onMouseMove(myCont As Object, _
  48. Button As Integer, _
  49. Shift As Integer, _
  50. X As Single, _
  51. Y As Single)
  52.  
  53. RaiseEvent MouseMove(myCont, Button, Shift, X, Y)
  54.  
  55. End Sub
  56. '*******************************************************************
  57. '
  58. Public Sub onChange(myCont As Object)
  59. RaiseEvent Change(myCont)
  60.  
  61. End Sub
  62. '*******************************************************************
  63. '
  64. Public Sub onKeyPress(myCont As Object, _
  65. KeyAscii As Integer)
  66.  
  67. RaiseEvent KeyPress(myCont, KeyAscii)
  68.  
  69. End Sub'--------------------------------------------------------------------
  70. '
  71. Public Sub onKeyDown(myCont As Object, _
  72. KeyCode As Integer, _
  73. Shift As Integer)
  74.  
  75. RaiseEvent KeyDown(myCont, KeyCode, Shift)
  76.  
  77. End Sub
  78. '*******************************************************************
  79. '
  80. Public Sub Init()
  81. Dim Ctrl As Control
  82. Dim Obj As Object
  83.  
  84. If myParent Is Nothing Then
  85. Exit Sub
  86. End If
  87.  
  88. Set Labels = New Dictionary
  89. Set TextBoxs = New Dictionary
  90. Set CheckBoxs = New Dictionary
  91. Set ComboBoxs = New Dictionary
  92. Set Buttons = New Dictionary
  93.  
  94. For Each Ctrl In myParent.Controls
  95. Select Case TypeName(Ctrl)
  96. Case "TextBox"
  97.  
  98. With New C_TextBox
  99. Set .Item = Ctrl
  100. Set .Parent = Me
  101. TextBoxs.Add Ctrl.Name, .Self
  102. End With
  103.  
  104. Case "Label"
  105. With New C_Label
  106. Set .Item = Ctrl
  107. Set .Parent = Me
  108. Labels.Add Ctrl.Name, .Self
  109. End With
  110.  
  111. Case "ComboBox"
  112.  
  113. With New C_ComboBox
  114. Set .Item = Ctrl
  115. Set .Parent = Me
  116. ComboBoxs.Add Ctrl.Name, .Self
  117. End With
  118.  
  119. Case "CheckBox"
  120.  
  121. With New C_CheckBox
  122. Set .Item = Ctrl
  123. Set .Parent = Me
  124. CheckBoxs.Add Ctrl.Name, .Self
  125. End With
  126.  
  127. Case "CommandButton"
  128.  
  129. With New C_Button
  130. Set .Item = Ctrl
  131. Set .Parent = Me
  132. Buttons.Add Ctrl.Name, .Self
  133. End With
  134.  
  135. End Select
  136. Next Ctrl
  137.  
  138. End Sub
  139. '*******************************************************************
  140. '
  141. Public Sub DEL()
  142. Dim Keys As Variant
  143.  
  144. For Each Keys In TextBoxs
  145. TextBoxs(Keys).DEL
  146. Next Keys
  147. Set TextBoxs = Nothing
  148.  
  149. For Each Keys In Labels
  150. Labels(Keys).DEL
  151. Next Keys
  152. Set Labels = Nothing
  153.  
  154. For Each Keys In ComboBoxs
  155. ComboBoxs(Keys).DEL
  156. Next Keys
  157. Set ComboBoxs = Nothing
  158.  
  159. For Each Keys In CheckBoxs
  160. CheckBoxs(Keys).DEL
  161. Next Keys
  162. Set CheckBoxs = Nothing
  163.  
  164. For Each Keys In Buttons
  165. Buttons(Keys).DEL
  166. Next Keys
  167. Set Buttons = Nothing
  168.  
  169. Set myParent = Nothing
  170.  
  171. End Sub

C_TextBox



   

COPY

  1. Option Explicit
  2. '-------------------------------------------------------------------
  3.  
  4. Private WithEvents myLabel As Access.Label
  5. Private myParent As C_Controls
  6. Private myIndex As Long'--------------------------------------------------------------------
  7. '
  8. Public Property Set Item(ByRef Obj As Access.Label)
  9.  
  10. Set myLabel = Obj
  11.  
  12. End Property'--------------------------------------------------------------------
  13. '
  14. Public Property Get Item() As Access.Label
  15.  
  16. Set Item = myLabel
  17.  
  18. End Property'--------------------------------------------------------------------
  19. '
  20. Public Property Set Parent(ByRef Obj As C_Controls)
  21.  
  22. Set myParent = Obj
  23.  
  24. End Property'--------------------------------------------------------------------
  25. '
  26. Public Property Let Index(ByVal val As Long)
  27.  
  28. myIndex = val
  29.  
  30. End Property'--------------------------------------------------------------------
  31. '
  32. Public Property Get Index() As Long
  33.  
  34. Index = myIndex
  35.  
  36. End Property'--------------------------------------------------------------------
  37. '
  38. Public Property Get Self() As Object
  39.  
  40. Set Self = Me
  41.  
  42. End Property'--------------------------------------------------------------------
  43. '
  44. Public Sub DEL()
  45.  
  46. Set myLabel = Nothing
  47. Set myParent = Nothing
  48.  
  49. End Sub'--------------------------------------------------------------------
  50. '
  51. Private Sub Class_Terminate()
  52.  
  53. Set myLabel = Nothing
  54. Set myParent = Nothing
  55.  
  56. End Sub'--------------------------------------------------------------------
  57. '
  58. Private Sub myLabel_Click()
  59.  
  60. Call myParent.onClick(myLabel)
  61.  
  62. End Sub'--------------------------------------------------------------------
  63. '
  64. Private Sub myLabel_DblClick(Cancel As Integer)
  65.  
  66. Call myParent.onDblClick(myLabel, Cancel)
  67.  
  68. End Sub'--------------------------------------------------------------------
  69. '
  70. Private Sub myLabel_MouseMove(Button As Integer, _
  71. Shift As Integer, _
  72. X As Single, _
  73. Y As Single)
  74.  
  75. Call myParent.onMouseMove(myLabel, Button, Shift, X, Y)
  76.  
  77. End Sub

C_TextBox



   

COPY

  1. Option Explicit
  2. '-------------------------------------------------------------------
  3. '
  4. Private WithEvents myTextBox As Access.TextBox
  5. Private myParent As C_Controls
  6. Private myIndex As Long
  7. '--------------------------------------------------------------------
  8. '
  9. Public Property Set Item(ByRef Obj As Access.TextBox)
  10.  
  11. Set myTextBox = Obj
  12.  
  13. End Property
  14. '--------------------------------------------------------------------
  15. '
  16. Public Property Get Item() As Access.TextBox
  17.  
  18. Set Item = myTextBox
  19.  
  20. End Property
  21. '--------------------------------------------------------------------
  22. '
  23. Public Property Set Parent(ByRef Obj As C_Controls)
  24.  
  25. Set myParent = Obj
  26.  
  27. End Property
  28. '--------------------------------------------------------------------
  29. '
  30. Public Property Let Index(ByVal val As Long)
  31.  
  32. myIndex = val
  33.  
  34. End Property
  35. '--------------------------------------------------------------------
  36. '
  37. Public Property Get Index() As Long
  38.  
  39. Index = myIndex
  40.  
  41. End Property
  42. '--------------------------------------------------------------------
  43. '
  44. Public Property Get Self() As Object
  45.  
  46. Set Self = Me
  47.  
  48. End Property
  49. '--------------------------------------------------------------------
  50. '
  51. Public Sub DEL()
  52.  
  53. Set myTextBox = Nothing
  54. Set myParent = Nothing
  55.  
  56. End Sub
  57. '--------------------------------------------------------------------
  58. '
  59. Private Sub Class_Terminate()
  60.  
  61. Set myTextBox = Nothing
  62. Set myParent = Nothing
  63.  
  64. End Sub
  65. '--------------------------------------------------------------------
  66. '
  67. Private Sub myTextBox_Change()
  68.  
  69. Call myParent.onChange(myTextBox)
  70.  
  71. End Sub
  72. '--------------------------------------------------------------------
  73. '
  74. Private Sub myTextBox_DblClick(Cancel As Integer)
  75.  
  76. Call myParent.onDblClick(myTextBox, Cancel)
  77.  
  78. End Sub'--------------------------------------------------------------------
  79. '
  80. Private Sub myTextBox_KeyPress(KeyAscii As Integer)
  81.  
  82. Call myParent.onKeyPress(myTextBox, KeyAscii)
  83.  
  84. End Sub
  85. '--------------------------------------------------------------------
  86. '
  87. Private Sub myTextBox_MouseMove(Button As Integer, _
  88. Shift As Integer, _
  89. X As Single, _
  90. Y As Single)
  91.  
  92. Call myParent.onMouseMove(myTextBox, Button, Shift, X, Y)
  93.  
  94. End Sub

C_Kyuzituクラス



   

COPY

  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Enum YobiType
  5. Shuku = 10
  6. Kokumin = 11
  7. Hurikae = 12
  8. Kanrei = 13
  9. End Enum
  10.  
  11. Private memShukuzitu As Dictionary
  12. Private memKokumin As Dictionary
  13. Private memHurikae As Dictionary
  14. Private memKanrei As Dictionary
  15. Private memYear As Long
  16. Private memMonth As Long
  17. Private memDay As Long
  18. Private memFormat As String
  19.  
  20. Public Property Let pYear(val As Long)
  21. Call KyuzituSet(val)
  22. End Property
  23.  
  24. Public Property Get pYear() As Long
  25. pYear = memYear
  26. End Property
  27.  
  28. Public Property Let SetStrDate(val As String)
  29.  
  30. If IsDate(val) Then
  31. Call KyuzituSet(CLng(DatePart("yyyy", val)))
  32. memMonth = CLng(DatePart("m", val))
  33. memDay = CLng(DatePart("d", val))
  34. Else
  35. Call KyuzituSet(1900)
  36. memMonth = 1
  37. memDay = 1
  38. End If
  39.  
  40. End Property
  41.  
  42. Public Property Let SetNumDate(val As Long)
  43.  
  44. Call KyuzituSet(Year(val))
  45. memMonth = Month(val)
  46. memDay = Day(val)
  47.  
  48. End Property
  49.  
  50. Public Property Let FormatFormat(val As String)
  51. memFormat = val
  52. End Property
  53.  
  54. Public Property Get GetStrDate() As String
  55. GetStrDate = Format(DateSerial(memYear, memMonth, memDay), memFormat)
  56. End Property
  57.  
  58. Public Property Get WeekNum() As Long
  59. WeekNum = Yobi
  60. End Property
  61.  
  62. Public Property Get DateNum() As Long
  63. DateNum = DateSerial(memYear, memMonth, memDay)
  64. End Property
  65.  
  66. Private Sub Class_Initialize()
  67.  
  68. Call KyuzituSet(Year(Date))
  69. memMonth = Month(Date)
  70. memDay = Day(Date)
  71.  
  72. End Sub
  73.  
  74. Private Sub Class_Terminate()
  75.  
  76. Set memShukuzitu = Nothing
  77. Set memKokumin = Nothing
  78. Set memHurikae = Nothing
  79. Set memKanrei = Nothing
  80.  
  81. End Sub
  82.  
  83. Private Function Yobi() As Long
  84.  
  85. If memShukuzitu.Exists(DateNum) Then
  86. Yobi = YobiType.Shuku
  87. Exit Function
  88. End If
  89.  
  90. If memKokumin.Exists(DateNum) Then
  91. Yobi = YobiType.Kokumin
  92. Exit Function
  93. End If
  94.  
  95. If memHurikae.Exists(DateNum) Then
  96. Yobi = YobiType.Kanrei
  97. Exit Function
  98. End If
  99.  
  100. If memKanrei.Exists(DateNum) Then
  101. Yobi = YobiType.Kanrei
  102. Exit Function
  103. End If
  104.  
  105. Yobi = Weekday(DateNum, vbSunday)
  106.  
  107. End Function
  108. '---------------------------------------
  109. Private Sub KyuzituSet(NewYear As Long)
  110.  
  111. If memYear <> NewYear Then
  112. memYear = NewYear
  113. Call makeShukuzitu
  114. Call makeKokumin
  115. Call makeHurikae
  116. Call makeKanrei
  117. End If
  118.  
  119. End Sub
  120. '---------------------------------------ロング値で与えられた日付の休日判定を行ないます。
  121. Private Sub makeShukuzitu()
  122. Dim iDay As Long
  123.  
  124. Set memShukuzitu = Nothing
  125. Set memShukuzitu = New Dictionary
  126.  
  127. '----------元日
  128. If DateSerial(memYear, 1, 1) > DateSerial(1948, 7, 19) Then
  129. memShukuzitu.Add DateSerial(memYear, 1, 1), "元旦"
  130. End If
  131. '----------成人の日 1月15日 → 1月の第2月曜
  132. If memYear > 1949 And memYear < 2000 Then
  133. memShukuzitu.Add DateSerial(memYear, 1, 15), "成人の日"
  134. ElseIf memYear > 1999 Then
  135. memShukuzitu.Add DateSerial(memYear, 1, 14) - Weekday(DateSerial(memYear, 1, 14), vbTuesday), "成人の日"
  136. End If
  137. '----------建国記念の日
  138. If DateSerial(memYear, 2, 11) > DateSerial(1948, 7, 19) Then
  139. memShukuzitu.Add DateSerial(memYear, 2, 11), "建国記念の日"
  140. End If
  141.  
  142. '----------天皇誕生日
  143. If memYear > 2019 Then
  144. memShukuzitu.Add DateSerial(memYear, 2, 23), "天皇誕生日"
  145. End If
  146.  
  147. '----------春分の日
  148. 'int(19.8277+0.242194*(年-1980)-int((年-1983)/4)) ----------1851-1899年通用
  149. 'int(20.8357+0.242194*(年-1980)-int((年-1983)/4)) ----------1900-1979年通用
  150. 'int(20.8431+0.242194*(年-1980)-int((年-1980)/4)) ----------1980-2099年通用
  151. 'int(21.8510+0.242194*(年-1980)-int((年-1980)/4)) ----------2100-2150年通用
  152. Select Case memYear
  153. Case Is < 2100
  154. iDay = Int(20.8431 + 0.242194 * (memYear - 1980) - Int((memYear - 1980) / 4))
  155. Case Is >= 2100
  156. iDay = Int(20.851 + 0.242194 * (memYear - 1980) - Int((memYear - 1980) / 4))
  157. End Select
  158. If DateSerial(memYear, 3, iDay) > DateSerial(1948, 7, 19) Then
  159. memShukuzitu.Add DateSerial(memYear, 3, iDay), "春分の日"
  160. End If
  161. '----------天皇誕生日→みどりの日→昭和の日
  162. If DateSerial(memYear, 4, 29) > DateSerial(1948, 7, 19) Then
  163. memShukuzitu.Add DateSerial(memYear, 4, 29), "昭和の日"
  164. End If
  165.  
  166. '----------即位の礼
  167. If memYear = 2019 Then
  168. memShukuzitu.Add DateSerial(memYear, 5, 1), "即位の礼"
  169. End If
  170.  
  171. '----------憲法記念日
  172. If DateSerial(memYear, 5, 3) > DateSerial(1948, 7, 19) Then
  173. memShukuzitu.Add DateSerial(memYear, 5, 3), "憲法記念日"
  174. End If
  175.  
  176. '----------みどりの日
  177. If memYear > 2006 Then
  178. memShukuzitu.Add DateSerial(memYear, 5, 4), "みどりの日"
  179. End If
  180. '----------こどもの日
  181. If DateSerial(memYear, 5, 5) > DateSerial(1948, 7, 19) Then
  182. memShukuzitu.Add DateSerial(memYear, 5, 5), "こどもの日"
  183. End If
  184.  
  185. '----------海の日 7月20日 → 7月の第3月曜日
  186. If memYear > 1995 And memYear < 2003 Then
  187. memShukuzitu.Add DateSerial(memYear, 7, 20), "海の日"
  188. ElseIf memYear > 2002 Then
  189. If memYear = 2020 Then
  190. 'オリンピックイヤー
  191. memShukuzitu.Add DateSerial(memYear, 7, 23), "海の日"
  192. ElseIf memYear = 2021 Then
  193. 'オリンピックイヤー
  194. memShukuzitu.Add DateSerial(memYear, 7, 22), "海の日"
  195. Else
  196. memShukuzitu.Add DateSerial(memYear, 7, 21) - Weekday(DateSerial(memYear, 7, 21), vbTuesday), "海の日"
  197. End If
  198. End If
  199.  
  200. '----------山の日"
  201. If memYear > 2015 Then
  202. If memYear = 2020 Then
  203. 'オリンピックイヤー
  204. memShukuzitu.Add DateSerial(memYear, 8, 10), "山の日"
  205. ElseIf memYear = 2021 Then
  206. 'オリンピックイヤー
  207. memShukuzitu.Add DateSerial(memYear, 8, 8), "山の日"
  208. Else
  209. memShukuzitu.Add DateSerial(memYear, 8, 11), "山の日"
  210. End If
  211. End If
  212. '----------敬老の日 9月15日 → 9月の第3月曜日
  213. If memYear > 1965 And memYear < 2003 Then
  214. memShukuzitu.Add DateSerial(memYear, 9, 15), "敬老の日"
  215. ElseIf memYear > 2002 Then
  216. memShukuzitu.Add DateSerial(memYear, 9, 21) - Weekday(DateSerial(memYear, 9, 21), vbTuesday), "敬老の日"
  217. End If
  218. '----------秋分の日
  219. 'int(22.2588+0.242194*(年-1980)-int((年-1983)/4)) ----------1851-1899年通用
  220. 'int(23.2588+0.242194*(年-1980)-int((年-1983)/4)) ----------1900-1979年通用
  221. 'int(23.2488+0.242194*(年-1980)-int((年-1980)/4)) ----------1980-2099年通用
  222. 'int(24.2488+0.242194*(年-1980)-int((年-1980)/4)) ----------2100-2150年通用
  223. Select Case memYear
  224. Case Is < 2100
  225. iDay = Int(23.2488 + 0.242194 * (memYear - 1980) - Int((memYear - 1980) / 4))
  226. Case Is >= 2100
  227. iDay = Int(24.2488 + 0.242194 * (memYear - 1980) - Int((memYear - 1980) / 4))
  228. End Select
  229. If DateSerial(memYear, 9, iDay) > DateSerial(1948, 7, 19) Then
  230. memShukuzitu.Add DateSerial(memYear, 9, iDay), "秋分の日"
  231. End If
  232. '----------体育の日 → スポーツの日 10月10日 → 10月の第二月曜日
  233. If memYear > 1965 And memYear < 2000 Then
  234. memShukuzitu.Add DateSerial(memYear, 10, 10), "体育の日"
  235. ElseIf memYear > 1999 Then
  236. If memYear = 2020 Then
  237. 'オリンピックイヤー
  238. memShukuzitu.Add DateSerial(memYear, 7, 24), "スポーツの日"
  239. ElseIf memYear = 2021 Then
  240. 'オリンピックイヤー
  241. memShukuzitu.Add DateSerial(memYear, 7, 23), "スポーツの日"
  242. Else
  243. memShukuzitu.Add DateSerial(memYear, 10, 14) - Weekday(DateSerial(memYear, 10, 14), vbTuesday), "スポーツの日"
  244. End If
  245. End If
  246.  
  247. '----------即位礼正殿の儀
  248. If memYear = 2019 Then
  249. memShukuzitu.Add DateSerial(memYear, 10, 22), "即位礼正殿の儀"
  250. End If
  251.  
  252. '----------文化の日
  253. If DateSerial(memYear, 11, 3) > DateSerial(1948, 7, 19) Then
  254. memShukuzitu.Add DateSerial(memYear, 11, 3), "文化の日"
  255. End If
  256.  
  257. '----------勤労感謝の日
  258. If DateSerial(memYear, 11, 23) > DateSerial(1948, 7, 19) Then
  259. memShukuzitu.Add DateSerial(memYear, 11, 23), "勤労感謝の日"
  260. End If
  261.  
  262. '----------天皇誕生日
  263. If memYear > 1988 And memYear < 2019 Then
  264. memShukuzitu.Add DateSerial(memYear, 12, 23), "天皇誕生日"
  265. End If
  266.  
  267. End Sub
  268.  
  269. Private Sub makeKokumin()
  270. Dim D() As Long
  271. Dim Keys As Variant
  272. Dim iCount As Long
  273. Dim I As Long
  274. Dim J As Long
  275. Dim Target As Long
  276.  
  277. If memShukuzitu.Count = 0 Then
  278. Exit Sub
  279. End If
  280.  
  281. If memYear < 1988 Then
  282. Exit Sub
  283. End If
  284.  
  285. Set memKokumin = Nothing
  286. Set memKokumin = New Dictionary
  287.  
  288. '-------------------------------国民の休日の判定
  289. ReDim D(memShukuzitu.Count - 1)
  290. For Each Keys In memShukuzitu
  291. D(iCount) = Keys
  292. iCount = iCount + 1
  293. Next
  294.  
  295. For I = 0 To UBound(D)
  296. For J = 0 To UBound(D)
  297. '-----------------------該当の組み合わせがある場合
  298. If D(J) - D(I) = 2 Then
  299. Target = (D(J) + D(I)) / 2
  300. If Not memShukuzitu.Exists(Target) Then
  301. memKokumin.Add Target, "休日"
  302. End If
  303. End If
  304. Next J
  305. Next I
  306.  
  307. End Sub
  308.  
  309. Private Sub makeHurikae()
  310. Dim iDay As Long
  311. Dim fDay As Long
  312. Dim boHurikae As Boolean
  313.  
  314. If memShukuzitu.Count = 0 Then
  315. Exit Sub
  316. End If
  317.  
  318. If memYear < 1973 Then
  319. Exit Sub
  320. End If
  321.  
  322. Set memHurikae = Nothing
  323. Set memHurikae = New Dictionary
  324.  
  325. For iDay = DateSerial(memYear, 1, 1) To DateSerial(memYear, 12, 31)
  326. '---------------------------日曜日であること
  327. If Weekday(iDay) = 1 Then
  328. '-------------------祝日であること
  329. If memShukuzitu.Exists(iDay) Then
  330. boHurikae = True
  331. fDay = iDay
  332. End If
  333. End If
  334.  
  335. '---------------------------フラッグを立てた後、最初の祝日でない日を振替日とする
  336. If boHurikae = True Then
  337. If iDay > fDay Then
  338. '-------------------祝休日に該当しない場合、振替日にする
  339. If Not memShukuzitu.Exists(iDay) Then
  340. memHurikae.Add iDay, "振替"
  341. boHurikae = False
  342. End If
  343. End If
  344. End If
  345.  
  346. Next iDay
  347.  
  348. End Sub
  349.  
  350. Private Sub makeKanrei()
  351.  
  352. Set memKanrei = Nothing
  353. Set memKanrei = New Dictionary
  354.  
  355. '-----------------------------------慣例になっている休日
  356. With memKanrei
  357. .Add DateSerial(memYear, 1, 1), "慣例"
  358. .Add DateSerial(memYear, 1, 2), "慣例"
  359. .Add DateSerial(memYear, 1, 3), "慣例"
  360. .Add DateSerial(memYear, 12, 31), "慣例"
  361. End With
  362.  
  363. End Sub