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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| Imports System.IO
Public Class Form1
Structure point
Dim x As Single
Dim y As Single
End Structure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'DECLARER un lecteur de fichier
Dim monlecteur As StreamReader
'DECLARER une collection pour les lignes du fichier
Dim meslignes As New ArrayList
'path est le chemin complet du fichier à lire
monlecteur = New StreamReader("D:\Projet-info\Projet.txt")
With monlecteur
'POSITIONNER le flux au début du fichier
.BaseStream.Seek(0, SeekOrigin.Begin)
'TANT QUE le lecteur a quelquechose à lire
While (.Peek > 0)
'LIRE une ligne du fichier et l'ajouter à meslignes
meslignes.Add(.ReadLine)
End While
End With
'calculer le nbr de ligne contenants dans le fichier txt
Dim lignes() As String = File.ReadAllLines("D:\Projet-info\Projet.txt")
Dim nLignes = lignes.Length
For i = 0 To nLignes - 1
TextBox1.Text &= meslignes(i) + vbCrLf
Next
'lire mot par mot et srocket dans un tableau mot()
Dim mot() As String = Nothing
Dim text = File.ReadAllText("D:\Projet-info\Projet.txt")
mot = text.Split(vbCrLf, " "c)
Dim nMots As Double = mot.Length
For i = 0 To nMots - 1
TextBox1.Text &= mot(i) '+ vbTab
Next
Label1.Text = nMots
'Using reader As New StreamReader("D:\Projet-info\Projet.txt")
monlecteur.Close()
End Sub
End Class |
Partager