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
| 'NG/23.11.10 ajoute un n° en tête de ligne pour gestion d'erreur
Private Sub add_no_Click()
Dim OFName As OPENFILENAME
Dim a As Integer
Dim FSO As New Scripting.FileSystemObject
Dim F1 As Scripting.TextStream, F2 As Scripting.TextStream
Dim T As String, s As String, i As Integer, suite As Boolean
'demande le fichier à traiter
OFName.lStructSize = Len(OFName) 'Set the structure size
OFName.hwndOwner = Me.hwnd 'Set the owner window
OFName.hInstance = Application.hWndAccessApp 'Set the application's instance
'Set the filet
OFName.lpstrFilter = "All Files (*.*)" + Chr$(0) + "*.txt" + Chr$(0)
OFName.lpstrFile = Space$(254) 'Create a buffer
OFName.nMaxFile = 255 'Set the maximum number of chars
OFName.lpstrFileTitle = Space$(254) 'Create a buffer
OFName.nMaxFileTitle = 255 'Set the maximum number of chars
OFName.lpstrInitialDir = "c:\planet" 'Set the initial directory
OFName.lpstrTitle = "Choix du fichier" 'Set the dialog title
OFName.flags = 0 'no extra flags
x_file = ""
If GetOpenFileName(OFName) Then
'on recupere 254 caracteres il faut limiter au fichier et trouver chr(0)
a = InStr(OFName.lpstrFile, Chr(0))
x_file = Left(OFName.lpstrFile, a - 1)
End If
If Len(x_file) = 0 Then MsgBox "Aucun fichier :(": Exit Sub
Call copie(x_file, Replace(x_file, "txt", "old"))
'MsgBox "Fichier à générer : " & x_file
i = 98
suite = False
Set F1 = FSO.OpenTextFile(Replace(x_file, "txt", "old"))
Set F2 = FSO.OpenTextFile(x_file, ForWriting, True)
'parcourt le fichier texte dans F1 et écrit dans F2
While Not F1.AtEndOfStream
T = F1.ReadLine
s = Trim(T)
If Left(s, 7) = "End Sub" Or Left(s, 7) = "End Fun" Then
i = 98
ElseIf Left(s, 4) = "Err:" Then
If InStr(T, "& Erl &") = 0 Then T = Replace(T, "err.Number", "err.Number & ""/"" & Erl")
ElseIf s = "" Or Left(s, 4) = "Dim " Or Left(s, 7) = "Public " Or Left(s, 8) = "Private " Or Left(s, 7) = "Option " _
Or Left(s, 8) = "Declare " Or s = "If Not Mode_debug Then On Error GoTo err:" Then
'rien
ElseIf suite Or s = "Else" Or s = "Exit Sub" Or s = "Exit Function" Or Left(s, 1) = "'" Or Left(s, 1) = "&" _
Or Left(s, 3) = "End" Or Left(s, 4) = "Wend" Or Left(s, 4) = "Next" Or Left(s, 5) = "Case " Then
If i > 98 Then T = " " & T
Else
i = i + 2
T = Format(i, "000") & " " & T
End If
F2.WriteLine T
suite = Right(s, 1) = "_"
Wend
F1.Close: Set F1 = Nothing
F2.Close: Set F2 = Nothing
Set FSO = Nothing
'Demande à l'utilisateur s'il veut visualiser le fichier
'If MsgBox("Voulez vous ouvrir le fichier généré ?", vbQuestion + vbYesNo) = vbYes Then
Shell "notepad.exe " & x_file, vbMaximizedFocus
'End If
End Sub |
Partager