Private Sub cmdSave_Click()
Dim vKeys As Variant
Dim vItems As Variant
Dim oFS As New FileSystemObject
Dim oTS As TextStream
Dim sTmpDir As String
Dim i As Integer
' Dictionary to Array
vKeys = oDic.Keys
vItems = oDic.Items
' Get Temp Dir
sTmpDir = oFS.GetSpecialFolder(TemporaryFolder).Path
' Open File
Set oTS = oFS.OpenTextFile(oFS.BuildPath(sTmpDir, DICFILE), ForWriting, True, TristateUseDefault)
' Save
For i = 0 To oDic.Count - 1
oTS.WriteLine vKeys(i)
oTS.WriteLine vItems(i)
Debug.Print oTS.Line, oTS.Column
Next i
oTS.Close
Set oTS = Nothing
End Sub
' テキストストリームからの読み込み
Private Sub cmdLoad_Click()
Dim oFS As New FileSystemObject
Dim oTS As TextStream
Dim sTmpDir As String
Dim i As Integer
Dim sKey As String
Dim sItem As String
' Get Temp Dir
sTmpDir = oFS.GetSpecialFolder(TemporaryFolder).Path
' Open File
Set oTS = oFS.OpenTextFile(oFS.BuildPath(sTmpDir, DICFILE), ForReading, False, TristateUseDefault)
' Load
oDic.RemoveAll
Do Until oTS.AtEndOfStream
sKey = oTS.ReadLine
sItem = oTS.ReadLine
oDic.Add sKey, sItem
Debug.Print oTS.Line, oTS.Column
Loop
oTS.Close
Set oTS = Nothing
DispAllKeys
End Sub
|