Originariamente inviato da Bifrost
Ho 1 grosso problema: io devo scrivere dei dati su un file .txt, ma continuo a riscontrare 1 errore 55 "file già in uso"... purtroppo questa è l'unica procedura che apre file, e non riesco a trovare soluzione... segue post del codice, anche se povero di commenti...(tra l'altro nell'anteprima ho notato che il codice perde tabulazione e risulta 1 pò incomprensibile...:-( spero che qualcono ci capisca qualcosa lo stesso)
Il codice risulta perdere di indentazione perchè non hai usato i tag [CODE*][/CODE*] (senza l'asterisco) per scriverlo. Altrimenti, avrebbe assunto questa forma:
codice:
Sub scrivi(frase As String, ind As Integer) 'frase = frase da scrivere, ind = index del winsok che ha mandato comando di scrittura
If scritturaOnOff = False Then
scritturaOnOff = True
file = FreeFile
On Error GoTo iol
Open "f:\log " & FormatDateTime(Now, vbLongDate) & ".txt" For Append As #file
Print #file, frase & " - DA : - " & Winsock1(ind).RemoteHostIP & " - SULLA PORTA: - " & Winsock1(ind).LocalPort & " - DATA: - " & FormatDateTime(Now, vbGeneralDate) & vbCrLf
Close #file
Text1 = frase & Winsock1(ind).RemoteHostIP & " - SULLA PORTA: - " & Winsock1(ind).LocalPort & " - DATA: - " & FormatDateTime(Now, vbGeneralDate) & vbCrLf & Text1
scritturaOnOff = False
Else
MsgBox ("non scritto: " & frase & " - DA : - " & Winsock1(ind).RemoteHostIP & " - SULLA PORTA: - " & Winsock1(ind).LocalPort & " - DATA: - " & FormatDateTime(Now, vbGeneralDate) & vbCrLf)
End If
Exit Sub
iol:
Text1 = "errore nella scrittura n° " & Err.Number & Err.Description & vbCrLf & frase & Winsock1(ind).RemoteHostIP & " - SULLA PORTA: - " & Winsock1(ind).LocalPort & " - DATA: - " & FormatDateTime(Now, vbGeneralDate) & vbCrLf & Text1
Resume Next
End Sub
Comunque, se non vado errato, il codice al di sotto dell'etichetta iol (etichetta compresa) andrebbe all'interno della Sub.
Ciao.