Error 55 "File already open". That's the error i get when my program tries to open the settings.dat file to update (write) the settings.
First of all, the program uses the "Get text from line" function in form load to get all the settings line-after-line. Here is the function it uses:
And then when the program updates the settings using the "UpdateSettings" function, the error appears at Open Environ("temp") & "\Settings.dat" For Output As #SettingsFileCode:Public Function GetTextFromLine(sFile As String, iLine As Long) As String Dim sText$, arText() As String, sLine$ Open sFile For Input As #1 'read entire file into a string variable sText = Input(LOF(1), #1) 'split text into array arText = Split(sText, vbNewLine) 'read specific line sLine = arText(iLine - 1) Close #1 GetTextFromLine = sLine End Function
Any idéa what's wrong?Code:Public Function UpdateSettings(WhatLine As String, TextString As String) If InStr(WhatLine, "1") Then Part1 = TextString End If If InStr(WhatLine, "2") Then Part2 = TextString End If TSettings = Part1 & vbNewLine & Part2 'Part 2 and Part 1 will be joined back in to TSettings.text Dim SettingsFile As Long SettingsFile = FreeFile() Open Environ("temp") & "\Settings.dat" For Output As #SettingsFile 'Here is the error. Write #SettingsFile, (TSettings) Close #SettingsFile End Function




Reply With Quote