Не могу понять в чем ошибка. Есть 2 формы, в 1й есть ListView - в него грузятся данные из тхт файла, во 2й форме происходит добавление новой инфы в тхт файл. Есть модуль, в котром есть 2 процедуры, соответственно 1я на загрузку инфы, 2я на добавление.
Загрузка:
| Код | Public Sub obnovlenie() Form1.ListView1.ListItems.Clear baza = App.path & "\db.txt" i = 1 p = 0 razdel = "|" nFreeFile = FreeFile Open baza For Input As #nFreeFile nFileLenght = FileLen(baza) If nFileLenght = 0 Then Close #nFreeFile Exit Sub Else Do Line Input #nFreeFile, strFileContent Do dlina = Len(strFileContent) nFilm = "" name_f = "" genre_f = "" format = "" video_f = "" audio_f = "" country_f = "" simvol = "" god_f = "" sub_f = ""
nFilm = Left(strFileContent, 3)
For i = 5 To dlina simvol = Mid(strFileContent, i, 1) If simvol = "|" Then p = i + 1 i = 0 Exit For End If Next i
For i = p To dlina simvol = Mid(strFileContent, i, 1) If simvol <> razdel Then name_f = name_f & simvol Else p = i + 1 i = 0 Exit For End If Next i
For i = p To dlina simvol = Mid(strFileContent, i, 1) If simvol <> razdel Then genre_f = genre_f & simvol Else p = i + 1 i = 0 Exit For End If Next i
For i = p To dlina simvol = Mid(strFileContent, i, 1) If simvol <> razdel Then format = format & simvol Else p = i + 1 i = 0 Exit For End If Next i
For i = p To dlina simvol = Mid(strFileContent, i, 1) If simvol <> razdel Then video_f = video_f & simvol Else p = i + 1 i = 0 Exit For End If Next i
For i = p To dlina simvol = Mid(strFileContent, i, 1) If simvol <> razdel Then audio_f = audio_f & simvol Else p = i + 1 i = 0 Exit For End If Next i
For i = p To dlina simvol = Mid(strFileContent, i, 1) If simvol <> razdel Then country_f = country_f & simvol Else p = i + 1 i = 0 Exit For End If Next i
For i = p To dlina simvol = Mid(strFileContent, i, 1) If simvol <> razdel Then god_f = god_f & simvol Else p = i + 1 i = 0 Exit For End If Next i
For i = p To dlina simvol = Mid(strFileContent, i, 1) sub_f = sub_f & simvol Next i
Loop Until dlina = dlina dbaz Loop Until EOF(1) = True Close #nFreeFile End If End Sub
|
Добавление:
| Код | Public Sub film_add() 'Проверка If Form2.Text1.Text = "" Or Form2.Text2.Text = "" Or Form2.Text3.Text = "" Or Form2.Text4.Text = "" Or Form2.Combo1.Text = "" Or Form2.ListView2.ListItems.Count = 0 Or Form2.ListView4.ListItems.Count = 0 Then MsgBox "Пожалуйста, заполните все поля!", vbOKOnly + vbInformation, "Видеотека ver. 1.0" Exit Sub End If 'Добавление фильма baza = App.path & "\db.txt" nFreeFile = FreeFile nFilm = 0 razdel = "|" Close #1 Open baza For Input As #nFreeFile nFileLenght = FileLen(baza) strFileContent = Input(nFileLenght, #nFreeFile) If strFileContent = Empty Then GoTo close_bd_empty Else GoTo close_bd End If close_bd_empty: Close #nFreeFile genre_rashirenie_country
'Если БД пуста Open baza For Output As #nFreeFile genre_rashirenie_country nFilm = 1 Print #nFreeFile, nFilm & " |" & Form2.Text5.Text & "|" & Form2.Text1.Text & "|" & film_genre & "|" & UCase(rashirenie) & "|" & Form2.Text2.Text & "|" & Form2.Text3.Text & "|" & film_country & "|" & Form2.Text4.Text & "|" & Form2.Combo1.Text close_bd: Close #nFreeFile
'Если БД <> Empty Open baza For Append As #nFreeFile genre_rashirenie_country nFilm = Form1.ListView1.ListItems.Count + 1 If nFilm < 10 Then Print #nFreeFile, nFilm & " " & " " & razdel & Form2.Text5.Text & "|" & Form2.Text1.Text & "|" & film_genre & "|" & UCase(rashirenie) & "|" & Form2.Text2.Text & "|" & Form2.Text3.Text & "|" & film_country & "|" & Form2.Text4.Text & "|" & Form2.Combo1.Text Close #nFreeFile ElseIf nFilm < 100 Then Print #nFreeFile, nFilm & " " & razdel & Text5.Text & "|" & Text1.Text & "|" & film_genre & "|" & UCase(rashirenie) & "|" & Text2.Text & "|" & Text3.Text & "|" & film_country & "|" & Text4.Text & "|" & Combo1.Text Close #nFreeFile Else Print #nFreeFile, nFilm & razdel & Text5.Text & "|" & Text1.Text & "|" & film_genre & "|" & UCase(rashirenie) & "|" & Text2.Text & "|" & Text3.Text & "|" & film_country & "|" & Text4.Text & "|" & Combo1.Text Close #nFreeFile End If
Unload Form2
Load Form1 End Sub
|
В конце каждой процедуры я закрываю файл. Но при добавлении новой инфы пишет ошибку file already open. Почему? Заранее благодарен. |