20260515指摘対応6
This commit is contained in:
@@ -29,7 +29,7 @@ Public Function GetCache(ByVal cacheName As String) As Object
|
||||
Dim cache As Object
|
||||
Set cache = GlobalCache(cacheName)
|
||||
If cache.Count = 0 Then
|
||||
Err.Raise 1001, "GetCache", "No cached data found for '" & cacheName & "'. Please load the cache first."
|
||||
Err.Raise ERR_CACHE_NOT_FOUND, "GetCache", "No cached data found for '" & cacheName & "'. Please load the cache first."
|
||||
End If
|
||||
|
||||
Set GetCache = cache
|
||||
@@ -38,8 +38,6 @@ End Function
|
||||
|
||||
' before RefreshCache, should validate
|
||||
Public Sub RefreshCache(ByVal cacheName As String)
|
||||
On Error GoTo RefreshError
|
||||
|
||||
If GlobalCache Is Nothing Then InitCacheManager
|
||||
If Not GlobalCache.Exists(cacheName) Then
|
||||
Set GlobalCache(cacheName) = CreateObject("Scripting.Dictionary")
|
||||
@@ -56,24 +54,19 @@ Public Sub RefreshCache(ByVal cacheName As String)
|
||||
Set loadedData = LookupO1Cache()
|
||||
ElseIf Contains(sheetConfDict("Enum"), cacheName) Then
|
||||
Set loadedData = LoadLookup("Enum", cacheName)
|
||||
Else
|
||||
Else
|
||||
Set loadedData = LoadLookup(cacheName, cacheName)
|
||||
End If
|
||||
|
||||
If Not loadedData Is Nothing Then
|
||||
Set GlobalCache(cacheName) = loadedData
|
||||
End If
|
||||
|
||||
Exit Sub
|
||||
|
||||
RefreshError:
|
||||
Err.Raise 1001, "RefreshCache", "Failed to load " & cacheName & " lookup cache: " & Err.Description
|
||||
End Sub
|
||||
|
||||
' Refresh M1_KukanD cache - nested dict {D: {F: [G]}}
|
||||
' Structure: { 交通機関区分[D]: { 利用区間発名[F]: [利用区間着名G] } }
|
||||
' Structure: { Transport type [D]: { Station from [F]: [Station to G] } }
|
||||
Private Function LookupM1KukanCache()
|
||||
Dim resultCache As Object
|
||||
Dim resultCache As Object
|
||||
Set resultCache = CreateObject("Scripting.Dictionary")
|
||||
|
||||
On Error GoTo ErrHandler
|
||||
@@ -82,17 +75,13 @@ Private Function LookupM1KukanCache()
|
||||
On Error Resume Next
|
||||
Set ws = ThisWorkbook.Worksheets("M1")
|
||||
On Error GoTo ErrHandler
|
||||
|
||||
If ws Is Nothing Then
|
||||
Set LookupM1KukanCache = resultCache
|
||||
Exit Function
|
||||
End If
|
||||
' ws exists, continue
|
||||
|
||||
Dim sheetConf As Object: Set sheetConf = sheetConfDict("M1")
|
||||
Dim startRow As Long: startRow = sheetConf("StartRow")
|
||||
Dim lastRow As Long: lastRow = GetLastDataRowInRange(ws)
|
||||
If lastRow < startRow Then
|
||||
Set LookupM2Cache = resultCache
|
||||
If lastRow < startRow Then
|
||||
Set LookupM1KukanCache = resultCache
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
@@ -104,13 +93,13 @@ Private Function LookupM1KukanCache()
|
||||
|
||||
If dValue = "" Or fValue = "" Then GoTo NextRow2
|
||||
|
||||
' Outer level: D column (交通機関区分)
|
||||
' D column (transport type)
|
||||
If Not resultCache.Exists(dValue) Then
|
||||
Dim innerDict As Object: Set innerDict = CreateObject("Scripting.Dictionary")
|
||||
resultCache.Add dValue, innerDict
|
||||
End If
|
||||
|
||||
' Inner level: F column (利用区間発名) -> array of G values
|
||||
' F column (station from) -> array of G values
|
||||
Set innerDict = resultCache(dValue)
|
||||
If Not innerDict.Exists(fValue) Then
|
||||
Dim arr As Object: Set arr = CreateObject("Scripting.Dictionary")
|
||||
@@ -129,15 +118,19 @@ NextRow2:
|
||||
Exit Function
|
||||
|
||||
ErrHandler:
|
||||
Err.Raise Err.Number, Err.Source, Err.Description
|
||||
If Err.Number = 9 Then ' Subscript out of range (sheet not found)
|
||||
Err.Raise ERR_SHEET_MISSING, "LookupM1KukanCache", "Sheet 'M1' not found."
|
||||
Else
|
||||
Err.Raise ERR_CACHE_NOT_FOUND, "LookupM1KukanCache", "Failed to load M1Kukan cache: " & Err.Description
|
||||
End If
|
||||
End Function
|
||||
|
||||
' ============================================================
|
||||
' M2 Cache - Nested Dictionary
|
||||
' Structure: { 区間コード[C]: { 券種[I]: { コード[J]: K } } }
|
||||
' Structure: { Section code [C]: { Ticket type [I]: { Code [J]: K } } }
|
||||
' ============================================================
|
||||
Private Function LookupM2Cache() As Object
|
||||
Dim resultCache As Object
|
||||
Dim resultCache As Object
|
||||
Set resultCache = CreateObject("Scripting.Dictionary")
|
||||
|
||||
On Error GoTo ErrHandler
|
||||
@@ -146,11 +139,7 @@ Private Function LookupM2Cache() As Object
|
||||
On Error Resume Next
|
||||
Set ws = ThisWorkbook.Worksheets("M2")
|
||||
On Error GoTo ErrHandler
|
||||
|
||||
If ws Is Nothing Then
|
||||
Set LookupM2Cache = resultCache
|
||||
Exit Function
|
||||
End If
|
||||
' ws exists, continue
|
||||
|
||||
Dim sheetConf As Object: Set sheetConf = sheetConfDict("M2")
|
||||
Dim startRow As Long: startRow = sheetConf("StartRow")
|
||||
@@ -195,25 +184,27 @@ NextRow:
|
||||
Exit Function
|
||||
|
||||
ErrHandler:
|
||||
Err.Raise Err.Number, Err.Source, Err.Description
|
||||
If Err.Number = 9 Then
|
||||
Err.Raise ERR_SHEET_MISSING, "LookupM2Cache", "Sheet 'M2' not found."
|
||||
Else
|
||||
Err.Raise ERR_CACHE_NOT_FOUND, "LookupM2Cache", "Failed to load M2 cache: " & Err.Description
|
||||
End If
|
||||
End Function
|
||||
|
||||
' ============================================================
|
||||
' O1 Cache
|
||||
' ============================================================
|
||||
Private Function LookupO1Cache() As Object
|
||||
Dim resultCache As Object
|
||||
Dim resultCache As Object
|
||||
Set resultCache = CreateObject("Scripting.Dictionary")
|
||||
|
||||
On Error GoTo ErrHandler
|
||||
|
||||
Dim ws As Worksheet
|
||||
On Error Resume Next
|
||||
Set ws = ThisWorkbook.Worksheets("O1")
|
||||
On Error GoTo ErrHandler
|
||||
|
||||
If ws Is Nothing Then
|
||||
Set LookupO1Cache = resultCache
|
||||
Exit Function
|
||||
End If
|
||||
' ws exists, continue
|
||||
|
||||
Dim sheetConf As Object: Set sheetConf = sheetConfDict("O1")
|
||||
Dim startRow As Long: startRow = sheetConf("StartRow")
|
||||
@@ -261,7 +252,11 @@ NextO1:
|
||||
Exit Function
|
||||
|
||||
ErrHandler:
|
||||
Err.Raise Err.Number, Err.Source, Err.Description
|
||||
If Err.Number = 9 Then
|
||||
Err.Raise ERR_SHEET_MISSING, "LookupO1Cache", "Sheet 'O1' not found."
|
||||
Else
|
||||
Err.Raise ERR_CACHE_NOT_FOUND, "LookupO1Cache", "Failed to load O1 cache: " & Err.Description
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Sub RefreshSheetDict()
|
||||
|
||||
Reference in New Issue
Block a user