1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| Public Class Form1
Public nl As Integer = 0 ' Nombre de lignes dans le fichier
Public nomfic As String = "Fic.txt"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
FileOpen(1, nomfic, OpenMode.Input)
Do Until EOF(1) ' Jusqu'à la fin du fichier
ListBox1.Items.Add(LineInput(1))
nl = nl + 1
Loop
Catch ex As Exception
MsgBox("Fichier absent ou en erreur : " & ex.ToString)
Finally
FileClose(1)
Label1.Text = nl.ToString & " lignes lues"
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
Try
FileOpen(1, nomfic, OpenMode.Append)
PrintLine(1, TextBox1.Text)
nl = nl + 1
Label1.Text = nl.ToString & " lignes"
TextBox1.Text = " "
Catch ex As Exception
MsgBox("Fichier absent ou en erreur : " & ex.ToString)
Finally
FileClose(1)
End Try
End Sub
End Class |