Soyez le premier à donner votre avis sur cette source.
Vue 10 660 fois - Téléchargée 608 fois
' Static-Toad - le 08/10/2002 ' Programme qui permet de lire un fichier texte en comptant ' le nombre de fois qu'apparaît chaque lettre Option Explicit Dim tablo(26) As Integer Dim test As String Dim chaine As String Dim chara As String Sub main() test = App.Path & "\test.txt" Open test For Input As 1 ' Ouverture du fichier Do While Not EOF(1) ' Continu à lire les caractères du ' fichier tant que l'on est pas à la fin chara = Input(1, 1) remplissage chara, tablo chaine = chaine & chara ' Rempli la chaîne de caractère ' qui donne le résultat final Loop With Form1 ' Affichage des résultats .Show .Label54 = chaine .Label2 = tablo(0) .Label52 = tablo(1) .Label51 = tablo(2) .Label50 = tablo(3) .Label49 = tablo(4) .Label48 = tablo(5) .Label47 = tablo(6) .Label46 = tablo(7) .Label45 = tablo(8) .Label44 = tablo(9) .Label43 = tablo(10) .Label42 = tablo(11) .Label41 = tablo(12) .Label40 = tablo(13) .Label39 = tablo(14) .Label38 = tablo(15) .Label37 = tablo(16) .Label36 = tablo(17) .Label35 = tablo(18) .Label34 = tablo(19) .Label33 = tablo(20) .Label32 = tablo(21) .Label31 = tablo(22) .Label30 = tablo(23) .Label29 = tablo(24) .Label28 = tablo(25) End With Close #1 ' Fermeture du fichier End Sub Public Sub remplissage(x As String, tableau() As Integer) Select Case x Case "a" tableau(0) = tableau(0) + 1 Case "b" tableau(1) = tableau(1) + 1 Case "c" tableau(2) = tableau(2) + 1 Case "d" tableau(3) = tableau(3) + 1 Case "e" tableau(4) = tableau(4) + 1 Case "f" tableau(5) = tableau(5) + 1 Case "g" tableau(6) = tableau(6) + 1 Case "h" tableau(7) = tableau(7) + 1 Case "i" tableau(8) = tableau(8) + 1 Case "j" tableau(9) = tableau(9) + 1 Case "k" tableau(10) = tableau(10) + 1 Case "l" tableau(11) = tableau(11) + 1 Case "m" tableau(12) = tableau(12) + 1 Case "n" tableau(13) = tableau(13) + 1 Case "o" tableau(14) = tableau(14) + 1 Case "p" tableau(15) = tableau(15) + 1 Case "q" tableau(16) = tableau(16) + 1 Case "r" tableau(17) = tableau(17) + 1 Case "s" tableau(18) = tableau(18) + 1 Case "t" tableau(19) = tableau(19) + 1 Case "u" tableau(20) = tableau(20) + 1 Case "v" tableau(21) = tableau(21) + 1 Case "w" tableau(22) = tableau(22) + 1 Case "x" tableau(23) = tableau(23) + 1 Case "y" tableau(24) = tableau(24) + 1 Case "z" tableau(25) = tableau(25) + 1 End Select End Sub
Dim Bit As Byte
tab1(65 To 122) As integer
Open App.Path & " est.txt" For Binary As 1
For i = 1 To LOF(1)
Get 1, i, Bit
If Bit <= 122 And Bit >= 97 Then
tab1(CInt(Bit)) = tab1(CInt(Bit)) + 1
Label1(CInt(Bit)).Caption = tab1(CInt(Bit))
ElseIf Bit <= 90 And Bit >= 65 Then
tab1(CInt(Bit)) = tab1(CInt(Bit)) + 1
Label1(CInt(Bit)).Caption = tab1(CInt(Bit))
End If
Next
Close 1
Remplace ton select case par :
Dim Lettre as integer
Lettre = Asc(lcase(x)) - Asc("a") 'optimisable avec les valeurs en dur
If Lettre >= 0 And Lettre < 26 Then
Tableau(Lettre) = Tableau(Lettre) + 1
End If
Pour l'affichage, tu fais une collection de label qui portent tous le même nom
For i = 0 To 25 Step 1
Label(i).Caption = Tableau(i)
Next
Pour finir, lit des blocs dans ton fichier puis traite les blocs avec un mid$, c'est 50 fois plus rapide...
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.