From 32420f8503fcb0cc97f9184d0d781a7e5be1f3bd Mon Sep 17 00:00:00 2001 From: updsv7 Date: Thu, 16 Apr 2026 19:13:22 +0900 Subject: [PATCH] add comment --- src/module/Generic_Master_Common.bas | 9 +- src/module/Global_Cache.bas | 94 ++++++++++++++------- src/module/Module_Common.bas | 13 ++- src/module/Read_Common.bas | 9 ++ src/module/Test_Cache.bas | 13 ++- src/module/Write_Common.bas | 8 ++ src/thisWorkbook/Master_M1_Kukan.bas | 14 +++ src/thisWorkbook/Master_M2_Kukan_detail.bas | 14 +++ src/thisWorkbook/Master_O1_address.bas | 9 ++ src/thisWorkbook/Master_O2_507.bas | 9 ++ src/thisWorkbook/Master_Z1_222.bas | 9 ++ src/thisWorkbook/Master_Z2_223.bas | 9 ++ src/thisWorkbook/Master_Z3_224.bas | 9 ++ src/thisWorkbook/Tukin_C1.bas | 14 +++ 14 files changed, 200 insertions(+), 33 deletions(-) diff --git a/src/module/Generic_Master_Common.bas b/src/module/Generic_Master_Common.bas index f9cd158..97142ba 100644 --- a/src/module/Generic_Master_Common.bas +++ b/src/module/Generic_Master_Common.bas @@ -1,6 +1,13 @@ ' ============================================================ -' Generic Master Common Functions +' Module Name: Generic_Master_Common +' Module Desc: Generic Master Import/Export functions +' Module Methods: +' - Generic_Master_Import +' - Generic_Master_Export +' - Generic_ClearDataRows +' - GetCSVHeader ' ============================================================ + Sub Generic_Master_Import(ByVal ws As Worksheet, ByVal expectedColumnCount As Long) On Error GoTo ErrorHandler diff --git a/src/module/Global_Cache.bas b/src/module/Global_Cache.bas index ad717c9..4f9a125 100644 --- a/src/module/Global_Cache.bas +++ b/src/module/Global_Cache.bas @@ -1,34 +1,38 @@ ' ============================================================ -' Modele Name: Global_Cache -' Modele Desc: Global Cache Module, Shared caches across all worksheets +' Module Name: Global_Cache +' Module Desc: Global Cache Module, Shared caches across all worksheets +' Module Methods: +' - RefreshM1Cache / ClearM1Cache +' - RefreshM1KukanDCache / ClearM1KukanDCache +' - RefreshM2Cache / ClearM2Cache +' - RefreshZ1Cache / ClearZ1Cache +' - RefreshZ2Cache / ClearZ2Cache +' - RefreshZ3Cache / ClearZ3Cache +' - RefreshO1Cache / ClearO1Cache +' - RefreshO2Cache / ClearO2Cache ' ============================================================ -' M1 cache - used by M2_Kukan_detail, Tukin_C1 +' Cache Variables Public m1Cache As Object - -' M1_KukanD cache - nested dict {D: {F: [G]}} Public m1KukanDCache As Object - -' Z1 cache - used by M1_Kukan Public z1Cache As Object - -' Z2 cache Public z2Cache As Object - -' Z3 cache Public z3Cache As Object - -' O1 cache - used by Tukin_C1 Public o1Cache As Object - -' O2 cache Public o2Cache As Object - -' M2 cache - nested dictionary for Tukin_C1 Public m2Cache As Object +' m1Cache - used by M2_Kukan_detail, Tukin_C1 +' m1KukanDCache - nested dict {D: {F: [G]}} +' z1Cache - used by M1_Kukan, Tukin_C1 +' z2Cache +' z3Cache +' o1Cache - used by Tukin_C1 +' o2Cache +' m2Cache - nested dictionary for Tukin_C1 + ' ============================================================ -' M1 Cache +' M1 Cache - { 区間コード[C]: [value1-7] } ' ============================================================ Public Sub RefreshM1Cache() Set m1Cache = Nothing @@ -230,19 +234,51 @@ End Sub ' ============================================================ Public Sub RefreshO1Cache() Set o1Cache = Nothing + Set o1Cache = CreateObject("Scripting.Dictionary") - On Error GoTo RefreshError - Set o1Cache = LoadLookup("O1", keyCol:=3, valueCols:=Array(5, 6), startRow:=7) + Dim wsO1 As Worksheet + On Error Resume Next + Set wsO1 = ThisWorkbook.Worksheets("O1") + If wsO1 Is Nothing Then Exit Sub On Error GoTo 0 - - If o1Cache Is Nothing Or o1Cache.Count = 0 Then - Err.Raise 1001, "RefreshO1Cache", "O1 reference data is empty" - End If - - Exit Sub - -RefreshError: - Err.Raise 1002, "RefreshO1Cache", "Failed to load O1 lookup cache: " & Err.Description + + Dim lastRow As Long + lastRow = wsO1.Cells(wsO1.Rows.Count, 3).End(xlUp).Row + If lastRow < 7 Then Exit Sub + + Dim r As Long + For r = 7 To lastRow + Dim cVal As String + cVal = Trim(wsO1.Cells(r, 3).Value) ' C column + Dim eVal As String + eVal = Trim(wsO1.Cells(r, 5).Value) ' E column + Dim fVal As String + fVal = Trim(wsO1.Cells(r, 6).Value) ' F column + + If cVal = "" Or eVal = "" Then GoTo NextO1 + + ' Outer: C column + If Not o1Cache.Exists(cVal) Then + Dim innerDict As Object + Set innerDict = CreateObject("Scripting.Dictionary") + o1Cache.Add cVal, innerDict + End If + + ' Inner: E column -> array of F values + Set innerDict = o1Cache(cVal) + If Not innerDict.Exists(eVal) Then + Dim arr As Object + Set arr = CreateObject("Scripting.Dictionary") + innerDict.Add eVal, arr + End If + + Set arr = innerDict(eVal) + If fVal <> "" And Not arr.Exists(fVal) Then + arr.Add fVal, True + End If + +NextO1: + Next r End Sub Public Sub ClearO1Cache() diff --git a/src/module/Module_Common.bas b/src/module/Module_Common.bas index 68d3ba1..337733b 100644 --- a/src/module/Module_Common.bas +++ b/src/module/Module_Common.bas @@ -1,6 +1,17 @@ ' ============================================================ +' Module Name: Module_Common +' Module Desc: Common utility functions for all modules +' Module Methods: +' - GetLastDataRowInRange +' - ClearDataRows +' - ClearDataRow +' - SortDataRows +' - ToggleAutoFilter +' - AutoFitColumnWidth +' - GetSaveCSVPath +' ============================================================ + ' Common Functions -' ============================================================ ' Get CSV header from specified row and columns Function GetCSVHeader(ByVal ws As Worksheet, ByVal colLetters As Variant, ByVal headerRow As Long) As Variant diff --git a/src/module/Read_Common.bas b/src/module/Read_Common.bas index 1e66ff6..f9a7e17 100644 --- a/src/module/Read_Common.bas +++ b/src/module/Read_Common.bas @@ -1,3 +1,12 @@ +' ============================================================ +' Module Name: Read_Common +' Module Desc: CSV read functions +' Module Methods: +' - SelectCSVFile +' - ReadCSVAs2DArrayStrict +' - ParseCSVLines +' ============================================================ + Function SelectCSVFile() As String Dim fileDialog As FileDialog Set fileDialog = Application.FileDialog(msoFileDialogFilePicker) diff --git a/src/module/Test_Cache.bas b/src/module/Test_Cache.bas index cc24928..9acf82e 100644 --- a/src/module/Test_Cache.bas +++ b/src/module/Test_Cache.bas @@ -1,7 +1,16 @@ ' ============================================================ +' Module Name: Test_Cache +' Module Desc: Debug module to print cache contents to Test_Cache sheet +' Module Methods: +' - Test_PrintAllCaches +' - PrintM1CacheToSheet +' - PrintM1KukanDCacheToSheet +' - PrintM2CacheToSheet +' - PrintZ1CacheToSheet +' - PrintO1CacheToSheet +' ============================================================ + ' Test Cache Module -' Debug: Print cache contents to Test_Cache sheet -' ============================================================ Sub Test_PrintAllCaches() Call RefreshM1Cache diff --git a/src/module/Write_Common.bas b/src/module/Write_Common.bas index 35b910c..52ce8c7 100644 --- a/src/module/Write_Common.bas +++ b/src/module/Write_Common.bas @@ -1,3 +1,11 @@ +' ============================================================ +' Module Name: Write_Common +' Module Desc: CSV write functions +' Module Methods: +' - GetSaveCSVPath +' - WriteCSVFromArray +' ============================================================ + Function GetSaveCSVPath(Optional ByVal defaultName As String = "") As String Dim savePath As String savePath = Application.GetSaveAsFilename( _ diff --git a/src/thisWorkbook/Master_M1_Kukan.bas b/src/thisWorkbook/Master_M1_Kukan.bas index 9b3d309..503eaac 100644 --- a/src/thisWorkbook/Master_M1_Kukan.bas +++ b/src/thisWorkbook/Master_M1_Kukan.bas @@ -1,3 +1,17 @@ +' ============================================================ +' Module Name: Master_M1_Kukan +' Module Desc: M1 Kukan master data management (import/export/validate) +' Module Methods: +' - M1_Import +' - M1_Export +' - M1_validateButton_Click +' - M1_SortDataRowsByC +' - M1_ToggleAutoFilter +' - M1_Worksheet_Change +' - M1_ValidateRow +' - M1_FillValidationDropdown +' - M1_ValidateAllRows +' ============================================================ ' ====== Constants ====== Const START_COL As Long = 3 ' C column Const END_COL As Long = 14 ' N column diff --git a/src/thisWorkbook/Master_M2_Kukan_detail.bas b/src/thisWorkbook/Master_M2_Kukan_detail.bas index 23eb46a..d0896c6 100644 --- a/src/thisWorkbook/Master_M2_Kukan_detail.bas +++ b/src/thisWorkbook/Master_M2_Kukan_detail.bas @@ -1,3 +1,17 @@ +' ============================================================ +' Module Name: Master_M2_Kukan_detail +' Module Desc: M2 Kukan detail master data management +' Module Methods: +' - M2_Import +' - M2_Export +' - M2_validateButton_Click +' - M2_SortDataRowsByC +' - M2_ToggleAutoFilter +' - M2_Worksheet_Change +' - M2_ValidateRow +' - M2_FillValidationDropdown +' - M2_ValidateAllRows +' ============================================================ ' ====== Constants ====== Const START_COL As Long = 3 ' C column Const END_COL As Long = 18 ' R column diff --git a/src/thisWorkbook/Master_O1_address.bas b/src/thisWorkbook/Master_O1_address.bas index aa9cf59..c754d71 100644 --- a/src/thisWorkbook/Master_O1_address.bas +++ b/src/thisWorkbook/Master_O1_address.bas @@ -1,3 +1,12 @@ +' ============================================================ +' Module Name: Master_O1_address +' Module Desc: O1 address master data management +' Module Methods: +' - O1_Import +' - O1_Export +' - O1_SortDataRowsByC +' - O1_ToggleAutoFilter +' ============================================================ Sub O1_Import() Dim filePath As String Dim lines As Variant diff --git a/src/thisWorkbook/Master_O2_507.bas b/src/thisWorkbook/Master_O2_507.bas index bffb63b..8845210 100644 --- a/src/thisWorkbook/Master_O2_507.bas +++ b/src/thisWorkbook/Master_O2_507.bas @@ -1,3 +1,12 @@ +' ============================================================ +' Module Name: Master_O2_507 +' Module Desc: O2 master data management (507) +' Module Methods: +' - O2_Import +' - O2_Export +' - O2_SortDataRowsByC +' - O2_ToggleAutoFilter +' ============================================================ ' ====== (507) ======= Sub O2_Import() Call Generic_Master_Import(Me, 13) diff --git a/src/thisWorkbook/Master_Z1_222.bas b/src/thisWorkbook/Master_Z1_222.bas index 65293af..e0bc4ff 100644 --- a/src/thisWorkbook/Master_Z1_222.bas +++ b/src/thisWorkbook/Master_Z1_222.bas @@ -1,3 +1,12 @@ +' ============================================================ +' Module Name: Master_Z1_222 +' Module Desc: Z1 master data management (222) +' Module Methods: +' - Z1_Import +' - Z1_Export +' - Z1_SortDataRowsByC +' - Z1_ToggleAutoFilter +' ============================================================ ' ====== (222) ======= ' ====== Constants ====== diff --git a/src/thisWorkbook/Master_Z2_223.bas b/src/thisWorkbook/Master_Z2_223.bas index 35f8430..e9c8951 100644 --- a/src/thisWorkbook/Master_Z2_223.bas +++ b/src/thisWorkbook/Master_Z2_223.bas @@ -1,3 +1,12 @@ +' ============================================================ +' Module Name: Master_Z2_223 +' Module Desc: Z2 master data management (223) +' Module Methods: +' - Z2_Import +' - Z2_Export +' - Z2_SortDataRowsByC +' - Z2_ToggleAutoFilter +' ============================================================ ' ====== (223) ======= ' ====== Constants ====== diff --git a/src/thisWorkbook/Master_Z3_224.bas b/src/thisWorkbook/Master_Z3_224.bas index 8d56a40..74612b8 100644 --- a/src/thisWorkbook/Master_Z3_224.bas +++ b/src/thisWorkbook/Master_Z3_224.bas @@ -1,3 +1,12 @@ +' ============================================================ +' Module Name: Master_Z3_224 +' Module Desc: Z3 master data management (224) +' Module Methods: +' - Z3_Import +' - Z3_Export +' - Z3_SortDataRowsByC +' - Z3_ToggleAutoFilter +' ============================================================ ' ====== (224) ======= ' ====== Constants ====== diff --git a/src/thisWorkbook/Tukin_C1.bas b/src/thisWorkbook/Tukin_C1.bas index 0a826e9..1386b90 100644 --- a/src/thisWorkbook/Tukin_C1.bas +++ b/src/thisWorkbook/Tukin_C1.bas @@ -1,3 +1,17 @@ +' ============================================================ +' Module Name: Tukin_C1 +' Module Desc: Commuter allowance editing sheet (no CSV import) +' Module Methods: +' - Tukin_ValidateRow +' - FillTransportFromM1KukanD +' - FillDepartureFromM1KukanD +' - FillArrivalFromM1KukanD +' - FillKukanFromM1 +' - FillKanshuFromM2 +' - FillCodeFromM2 +' - FillAddressFromO1 +' - FillZ1Dropdown +' ============================================================ ' ====== (Tukin_C1) ======= ' Commuter allowance editing sheet ' No CSV import - direct editing only