Collection - Problem

P

Paul

Hay NG!

I want to read an ini-file an put all lines in a collectionobject.
everything is alright if i search the coll-object with an numeric index
if i try to do this with an alpha-key i got an error(5)

here my code
public colINI as Collection

Public Function BReadINIFile() As Boolean
Dim sBuffer As String, sSectionName As String, sKey As String
Dim sColKey As String, sColValue As String
Dim iX As Integer
Dim v As Variant, s As String

On Error GoTo fuError
BReadINIFile = False
set colINI=new Collection
Open m_sINIFileName For Input As #1

While Not EOF(1)
Line Input #1, sBuffer
If (sBuffer <> "") Then
If (Left$(sBuffer, 1) = "[") Then
iX = InStr(sBuffer, "]")
sSectionName = Left$(sBuffer, iX)
Else
iX = InStr(sBuffer, "=")
sKey = Left$(sBuffer, iX - 1)
sColKey = sSectionName & "[" & sKey & "]"
sColValue = Right$(sBuffer, Len(sBuffer) - iX)
colINI.Add Item:=Trim$(CStr(sColValue)),
Key:=Trim$(CStr(sKey))
End If
End If
Wend
Close #1
'only for testing i tried to get the last added key !
s = colINI.Item(CStr(sColKey))
BReadINIFile = True
fuExit:
Exit Function
fuError:
vShowError "BReadINIFile"
GoTo fuExit
End Function

whats wrong ?

thx for your help!

Paul
 
J

Jonathan West

Could it be that your INI file has multiple sections, and that there are
identical key names in more then one section?
 
P

Paul

hay jonathan - thx for your answer!

no there aren't duplicate keys - here's my ini-file

[PrtEvent]
LOG-Drive=C
LOG-UNC-Server=
LOG-Path=temp\DB-Prtevent
LOG-Ext=txt

i made a new collection-object and inserted 3 lines - i tested it with
col.item("alpha") - and it was alright - hhmm.
i tested the old collection without '[' maybe thats not allowed - but the
same error 5.
i tried it with types of string, variant ... always error 5
i tried it with trim / cstr without trim / cstr ... always the same error
:-((

i get crazy with collection - object !!!

thx
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top