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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
IndexFichier = FreeFile()
Open MonFichier For Input As #IndexFichier 'ouvre le fichier
While Not EOF(IndexFichier) '
Line Input #IndexFichier, ContenuLigne
i = i + 1
ii = ii + 1
ReDim Preserve Lignes(1 To ii)
Lignes(ii) = ContenuLigne
Wend
'' lecture du fichier
Lignes = LireFichier(MonFichier)
IndLignes = Left(Lignes(1), 1)
'MsgBox IndLignes
MsgBox Left(TextBox4.Value, 2)
Close #IndexFichier
'Application.ScreenUpdating = True
titi = StrConv(TextBox4.Text, vbFromUnicode)
'For i = 0 To UBound(titi)
'MsgBox Chr(titi(i))
'Next
s_indice = TextBox4.Value
s_testTypeInd = testTypeInd(s_indice)
V = Len(TextBox4.Value) 'Longueur du texte
NR = Right(TextBox4.Value, 1) 'renvoie le premier caratère à doite
NL = Left(TextBox4.Value, 1) 'renvoie le premier caratère à gauche
If s_testTypeInd = "majeur" Then
If NR = "A" Then
'MsgBox "A ecrire sur 1er ligne"
Open MonFichier For Output As #1
Print #1, Texte
Print #1,
Close #1
ElseIf NR = "B" Then
'MsgBox " A écrire sur la seconde ligne"
'' Si pas d'erreur on peut faire une modification sur une ligne.
If Lignes(1) <> "NOK" Then
Open MonFichier For Output As #1
Print #1, Lignes(1)
Print #1, Texte
Close #1
End If
ElseIf NR = "C" Then
'MsgBox " A écrire la 3"
'' Si pas d'erreur on peut faire une modification sur une ligne.
If Lignes(1) <> "NOK" Then
Open MonFichier For Output As #1
Print #1, Lignes(1)
Print #1, Lignes(2)
Print #1, Texte
Close #1
End If
Else
MsgBox "Pas encore fait"
End If
ElseIf s_testTypeInd = "mineur" Then
'MsgBox "Mineur"
If IsNumeric(NL) Then
N1 = CInt(NL)
End If
If IsNumeric(NR) Then
N1 = CInt(NR)
End If
'MsgBox " Indice Mineur" & NL & NR
If TextBox4 = "1A" Then
Open MonFichier For Output As #1
Print #1, Texte
Close #1
End If
If NL <> "1" And NR <> "1" And Left(Lignes(1), 1) <> "A" Then
Open MonFichier For Append As #1
Print #1, Texte
Close #1
ElseIf Left(Lignes(1), 1) = "A" And TextBox4 <> "1A" And NL <> "1" And NR <> "1" Then
Open MonFichier For Append As #1
Print #1, Texte
Close #1
ElseIf Left(Lignes(1), 1) = "A" And ii = 1 And TextBox4 <> "1A" Then
Open MonFichier For Output As #1
Print #1, Lignes(1)
Print #1, Texte
Close #1
ElseIf NL <> "1" And NR <> "1" And Left(Lignes(1), 1) = "A" And Left(Lignes(2), 1) <> "B" Then
Open MonFichier For Append As #1
Print #1, Texte
Close #1
ElseIf Left(Lignes(1), 1) = "A" And Left(Lignes(2), 1) = "B" And TextBox4 <> "1B" And NL <> "1" And NR <> "1" Then
Open MonFichier For Append As #1
Print #1, Texte
Close #1
ElseIf Left(Lignes(1), 1) = "A" And Left(Lignes(2), 1) = "B" And TextBox4 <> "1B" Then
Open MonFichier For Output As #1
Print #1, Lignes(1)
Print #1, Lignes(2)
Print #1, Texte
Close #1
ElseIf NL <> "1" And NR <> "1" And Left(Lignes(1), 1) = "A" And Left(Lignes(2), 1) <> "B" And Left(Lignes(3), 1) <> "C" Then
Open MonFichier For Append As #1
Print #1, Texte
Close #1
ElseIf Left(Lignes(1), 1) = "A" And Left(Lignes(2), 1) = "B" And Left(Lignes(3), 1) <> "C" And TextBox4 <> "1C" And NL <> "1" And NR <> "1" Then
Open MonFichier For Append As #1
Print #1, Texte
Close #1
ElseIf Left(Lignes(1), 1) = "A" And Left(Lignes(2), 1) = "B" And Left(Lignes(3), 1) <> "C" And TextBox4 <> "1C" Then
Open MonFichier For Output As #1
Print #1, Lignes(1)
Print #1, Lignes(2)
Print #1, Texte
Close #1
ElseIf NL <> "1" And NR <> "1" And Left(Lignes(1), 1) = "A" And Left(Lignes(2), 1) <> "B" And Left(Lignes(3), 1) <> "C" And Left(Lignes(4), 1) <> "D" Then
Open MonFichier For Append As #1
Print #1, Texte
Close #1
ElseIf Left(Lignes(1), 1) = "A" And Left(Lignes(2), 1) = "B" And Left(Lignes(3), 1) <> "C" And Left(Lignes(4), 1) <> "D" And TextBox4 <> "1C" And NL <> "1" And NR <> "1" Then
Open MonFichier For Append As #1
Print #1, Texte
Close #1
ElseIf Left(Lignes(1), 1) = "A" And Left(Lignes(2), 1) = "B" And Left(Lignes(3), 1) <> "C" And Left(Lignes(4), 1) <> "D" And TextBox4 <> "1D" Then
Open MonFichier For Output As #1
Print #1, Lignes(1)
Print #1, Lignes(2)
Print #1, Texte
Close #1
If Asc(Mid(TextBox4.Value, 2, 1)) > 68 Then
MsgBox "Pas fait!!!!!!"
End If
End If 'MsgBox "Mauvaise Saisie"
ElseIf V >= 2 And 65 >= titi(0) And titi(0) <= 90 And 65 >= titi(1) And titi(1) <= 90 And Not IsNumeric(NL) And Not IsNumeric(NR) Then
MsgBox " Indice Majeur" & NL & NR
End If
Public Function testAscii(Letter As String) As String
Letter = Left(Letter, 1)
If Asc(Letter) >= 65 And Asc(Letter) <= 90 Then
testAscii = "L"
ElseIf Asc(Letter) >= 48 And Asc(Letter) <= 57 Then
testAscii = "N"
Else
testAscii = "O"
End If
End Function
Public Function testTypeInd(s_indice As String) As String
If testAscii(Left(s_indice, 1)) = "N" Then
testTypeInd = "mineur"
ElseIf testAscii(Right(s_indice, 1)) = "N" Then
testTypeInd = "mineur"
Else
testTypeInd = "majeur"
End If
End Function
Public Function LireFichier(MonFichier As String, Optional NumLigneMin As Long, Optional NumLigneMax As Long) As Variant
Application.ScreenUpdating = False
On Error GoTo CodeErreur
Dim IndexFichier As Integer
Dim ContenuLigne As String
Dim i As Integer
Dim ii As Integer
Dim Lignes() As Variant
Dim Lignesbis As Variant
Dim j As Integer
Dim NumLigneMinBis, NumLigneMaxBis As Long
If NumLigneMin = 0 Then
NumLigneMin = 1
End If
If NumLigneMax = 0 Then
NumLigneMax = 9999999
End If
If NumLigneMin > NumLigneMax Then
If NumLigneMin > NumLigneMax Then
NumLigneMinBis = NumLigneMin
NumLigneMaxBis = NumLigneMax
End If
NumLigneMax = NumLigneMin
NumLigneMin = NumLigneMaxBis
End If
IndexFichier = FreeFile()
Open MonFichier For Input As #IndexFichier 'ouvre le fichier
While Not EOF(IndexFichier) '
Line Input #IndexFichier, ContenuLigne
i = i + 1
If i >= NumLigneMin And i <= NumLigneMax Then
ii = ii + 1
ReDim Preserve Lignes(1 To ii)
Lignes(ii) = ContenuLigne
End If
Wend
Close #IndexFichier ' ferme le fichier
Application.ScreenUpdating = True
j = 0
If NumLigneMinBis <> 0 And NumLigneMaxBis <> 0 Then
Lignesbis = Lignes
For i = UBound(Lignesbis) To 1 Step -1
j = j + 1
Lignes(j) = Lignesbis(i)
Next i
End If
If ii = 0 Then
ReDim Lignes(1 To 1)
Lignes(1) = "NOK"
End If
LireFichier = Lignes
Exit Function
CodeErreur:
MsgBox "Une erreur s'est produite..."
Application.ScreenUpdating = True
ReDim Lignes(1 To 1)
Lignes(1) = "NOK"
LireFichier = Lignes
End Function |