Sub WriteProfileString(section, key, filename, value) If MyTrim(section) = "" Or MyTrim(key) = "" Then Exit Sub End If Dim contentini contentini = "" If fso.FileExists(filename) Then Dim readini, bsection, bSectionFound, bKeyFound bKeyFound = False bsection = False bSectionFound = False Set readini = fso.OpenTextFile(filename, 1) Do While Not (readini.AtEndOfStream) Dim strini, trimstrini strini = readini.ReadLine trimstrini = MyTrim(strini) If Left(trimstrini, 1) = "[" And Right(trimstrini, 1) = "]" Then If StrComp(trimstrini, "[" & MyTrim(section) & "]", 1) = 0 Then bsection = True bSectionFound = True Else bsection = False End If Else If bsection Then Dim poskey poskey = InStr(trimstrini, "=") If poskey > 0 Then If StrComp(MyTrim(Left(trimstrini, poskey - 1)), MyTrim(key), 1) = 0 Then bKeyFound = True strini = Left(trimstrini, poskey) & " " & value End If End If End If End If If bSectionFound = True And bsection = False And bKeyFound = False Then contentini = contentini & key & "=" & value & vbCrLf bKeyFound = True End If If MyTrim(strini) <> "" Then If Left(trimstrini, 1) = "[" And Right(trimstrini, 1) = "]" And contentini <> "" Then contentini = contentini & vbCrLf End If contentini = contentini & strini & vbCrLf End If Loop If bSectionFound = True And bsection = True And bKeyFound = False Then contentini = contentini & key & "=" & value & vbCrLf End If If bSectionFound = False Then contentini = contentini & vbCrLf & "[" & section & "]" & vbCrLf & key & "=" & value & vbCrLf End If readini.Close Else contentini = "[" & section & "]" & vbCrLf & key & "=" & value & vbCrLf End If Dim writeini Set writeini = fso.CreateTextFile(filename, True) writeini.Write contentini writeini.Close End Sub