@@ -34,11 +34,11 @@ Public Class IniFile
3434 Return False
3535 End If
3636
37- fs = New FileStream(m_sPathFileName, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read )
37+ fs = New FileStream(m_sPathFileName, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite )
3838 sr = New StreamReader(fs, Encoding.UTF8)
3939
4040 While True
41- sLine = sr.ReadLine()
41+ sLine = Trim( sr.ReadLine() )
4242
4343 m_nItemsCount = m_nItemsCount + 1
4444
@@ -98,7 +98,7 @@ Public Class IniFile
9898 Next
9999
100100
101- fs = New FileStream(m_sPathFileName, FileMode.Create, FileAccess.Write, FileShare.None )
101+ fs = New FileStream(m_sPathFileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite )
102102 sw = New StreamWriter(fs, Encoding.UTF8)
103103
104104 sw.Write(sWrite)
@@ -145,9 +145,7 @@ Public Class IniFile
145145 nPos = InStr(sRetVal, "=" )
146146
147147 If (nPos > 0 ) Then
148- sRetVal = sRetVal.Substring(nPos)
149- Else
150-
148+ sRetVal = Trim(sRetVal.Substring(nPos))
151149 End If
152150
153151 Return sRetVal
@@ -157,6 +155,7 @@ Public Class IniFile
157155 Dim nIndex As Integer
158156
159157 Key = Trim( Key )
158+ value = Trim(value)
160159
161160 If Key = "" Then
162161 Err.Raise(INIFILE_ERR_KEY_REQUIRED, , "Missing key parameter" )
@@ -179,17 +178,29 @@ Public Class IniFile
179178
180179 Private Function _GetIndex( ByVal Key As String ) As Int32
181180 Dim i As Integer
182- Dim sSearchKey As String
181+ Dim sItem As String
182+ Dim sCheckKey As String
183183 Dim nPos As Int32
184184
185- sSearchKey = Key & "=" '-- "key="
185+
186+ Key = LCase( Key )
186187
187188 For i = 1 To m_nItemsCount
188- nPos = InStr(LTrim(m_aItems(i - 1 )), sSearchKey, CompareMethod.Text)
189+ sItem = m_aItems(i - 1 )
190+
191+ If Left(sItem, 1 ) <> ";" Then '-- Ignore remark char ";"
192+ nPos = InStr(sItem, "=" ) '-- Find "=" char
193+
194+ If nPos > 0 Then
195+ '-- Get Key
196+ sCheckKey = Trim(LCase(Left(m_aItems(i - 1 ), nPos - 1 )))
197+
198+ If sCheckKey = Key Then
199+ '-- Return actual array index (zero based array)
200+ Return (i - 1 )
201+ End If
202+ End If
189203
190- If nPos = 1 Then
191- '-- Return actual array index (zero based array)
192- Return (i - 1 )
193204 End If
194205 Next
195206
0 commit comments