Bonjour, j'ai fait un petit projet, qui est d'ailleur fonctionnel. J'aimerais seulement vérifier si mon code peu être optimisé que sa soit pour la lisibilité, la vitesse surtout ou bien le bon nommage des fonctions.
J'attend vos suggestions. Ce code est fonctionnel en passant. Merci.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Imports System.IO
 
Module Main
    Private ReadOnly PDefAcom As String = Application.StartupPath & "\PDefAcom.ini"
    Private ReadOnly PrntAcom As String = Application.StartupPath & "\PrntAcom.ini"
    'Liste des lignes de configuration dans le fichier avec un nom d'imprimante
    Private ReadOnly configline() As Integer = {8, 25, 42, 59, 100, 139, 178, 218, 257, 296, 327, 342, 351, 366, 381, 396, 411, 426, 491, 517, 527}
 
    Public Sub main(ByVal args() As String)
 
        Try
 
            If args.Length = 2 And IsNumeric(args(1)) Then
                corrigerfichierpdef(args(0), args(1), PDefAcom)
                corrigerfichierprnt(args(0), args(1), PrntAcom)
            Else
                Throw New Exception("Paramètres spécifiés invalides")
            End If
 
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            Application.Exit()
        End Try
 
    End Sub
 
    Private Sub corrigerfichierpdef(computer As String, sessionID As String, pathpdef As String)
        Dim currentline As String = Nothing, UserConfigLine As Integer = 0, modification As Boolean = False, Lignes As List(Of String) = Nothing
 
        Try
 
            If Not File.Exists(pathpdef) Then Throw New Exception("L'emplacement " & pathpdef & " est introubable.")
 
            Lignes = File.ReadLines(pathpdef).ToList()
 
            Do Until UserConfigLine >= Lignes.Count + 1
 
                'Le c sert déffinir explicitement le char
                If Lignes(UserConfigLine).Trim("["c, "]"c) = computer Then
 
                    For I As Integer = 0 To configline.Length - 1
                        currentline = Lignes(UserConfigLine + configline(I))
 
                        If Not currentline.IndexOf("(from") = -1 Then
 
                            Lignes(UserConfigLine + configline(I)) = currentline.Remove(InStrRev(currentline, " ")) & sessionID
                            modification = True
 
                        End If
 
                    Next
 
                End If
                UserConfigLine += 529
            Loop
 
            If modification = True Then File.WriteAllLines(pathpdef, Lignes)
 
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
 
    End Sub
 
 
    Private Sub corrigerfichierprnt(computer As String, sessionID As String, pathpdef As String)
        Dim txtcurrentline As String = Nothing, intcurrentline As Integer = 0, modification As Boolean = False, Lignes As List(Of String) = Nothing
 
        Try
 
            If Not File.Exists(pathpdef) Then Throw New Exception("L'emplacement " & pathpdef & " est introubable.")
 
            Lignes = File.ReadLines(pathpdef).ToList()
 
            Do Until intcurrentline >= Lignes.Count
 
                If Lignes(intcurrentline).StartsWith("[") Then
 
                    txtcurrentline = Lignes(intcurrentline)
 
                    If Not txtcurrentline.IndexOf("(from " & computer) = -1 Then
 
                        Lignes(intcurrentline) = txtcurrentline.Remove(InStrRev(txtcurrentline, " ")) & sessionID & "]"
                        modification = True
 
                    End If
 
                End If
                intcurrentline += 1
            Loop
 
            If modification = True Then File.WriteAllLines(pathpdef, Lignes)
 
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
 
    End Sub
 
End Module