Function Trace(ByVal sChaine) On Error Resume Next Dim iCounter As String iCounter = ListBox2.Items.Count() + 1 If (CInt(iCounter) < 10) Then iCounter = "[000" & iCounter & "] " ElseIf (iCounter < 100) Then iCounter = "[00" & iCounter & "] " ElseIf (iCounter < 1000) Then iCounter = "[0" & iCounter & "] " Else iCounter = "[" & iCounter & "] " End If Trace = ListBox2.Items.Add(iCounter & sChaine) ListBox2.SetSelected(ListBox2.Items.Count() - 1, True) ListBox2.TopIndex = ListBox2.Items.Count() - 1 'If (RichTextBox1.Text = "") Then ' RichTextBox1.AppendText(iCounter & sChaine) 'Else ' RichTextBox1.AppendText(vbCrLf & iCounter & sChaine) 'End If 'RichTextBox1.ScrollToCaret() If Err.Number > 0 Then Call procErrmsg(Err.Number, "00005 - " & Err.Description) Exit Function End If End Function Private Sub procErrmsg(ByVal numErr As Integer, ByVal msgErr As String) 'MsgBox(msgErr, vbExclamation, "Erreur: " & numErr) Trace("Erreur : " & msgErr) End Sub Private Delegate Sub DelegateProgressBarFormSplashScreen(ByVal NbMaxEtape As Long, ByVal nEtapeExecuter As Integer, ByVal percent As Integer, ByVal CurrLabel As Object, ByVal CurrProgressBar As Object) Public Sub ChangeProgressBar(ByVal NbMaxEtape As Long, ByVal nEtapeExecuter As Integer, ByVal percent As Integer, ByVal CurrLabel As Object, ByVal CurrProgressBar As Object) If (Me.InvokeRequired) Then Dim vChangeProgressBar As New DelegateProgressBarFormSplashScreen(AddressOf ChangeProgressBar) Me.Invoke(vChangeProgressBar) Else CurrProgressBar.Value = percent CurrLabel.Text = percent & "%" Application.DoEvents() End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim percent As Short Dim nEtapeExecuter As Integer = 1 Dim NbMaxEtape As Integer = 4 Dim ProgressBarFormSplashScreenDelegate As New DelegateProgressBarFormSplashScreen(AddressOf ChangeProgressBar) percent = (nEtapeExecuter / NbMaxEtape) * 100 Me.Invoke(ProgressBarFormSplashScreenDelegate, NbMaxEtape, nEtapeExecuter, percent, Form2.Label1, Form2.ProgressBar1) FonctionEtape1() nEtapeExecuter += 1 percent = (nEtapeExecuter / NbMaxEtape) * 100 Me.Invoke(ProgressBarFormSplashScreenDelegate, NbMaxEtape, nEtapeExecuter, percent, Form2.Label1, Form2.ProgressBar1) FonctionEtape2() nEtapeExecuter += 1 percent = (nEtapeExecuter / NbMaxEtape) * 100 Me.Invoke(ProgressBarFormSplashScreenDelegate, NbMaxEtape, nEtapeExecuter, percent, Form2.Label1, Form2.ProgressBar1) FonctionEtape3() nEtapeExecuter += 1 percent = (nEtapeExecuter / NbMaxEtape) * 100 Me.Invoke(ProgressBarFormSplashScreenDelegate, NbMaxEtape, nEtapeExecuter, percent, Form2.Label1, Form2.ProgressBar1) FonctionEtape4() nEtapeExecuter += 1 Me.Invoke(ProgressBarFormSplashScreenDelegate, 0, 0, 0, Form2.Label1, Form2.ProgressBar1) 'Fin du processus End Sub Private Sub FonctionEtape1() For i = 0 To 5000 Trace("Fonction Etape 1 : " & i) Next End Sub Private Sub FonctionEtape2() For i = 0 To 5000 Trace("Fonction Etape 2 : " & i) Next End Sub Private Sub FonctionEtape3() For i = 0 To 5000 Trace("Fonction Etape 3 : " & i) Next End Sub Private Sub FonctionEtape4() For i = 0 To 5000 Trace("Fonction Etape 4 : " & i) Next End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Delegate Sub DelegateProgressBarFormSplashScreen(ByVal NbMaxEtape As Long, ByVal nEtapeExecuter As Integer, ByVal percent As Integer, ByVal CurrLabel As Object, ByVal CurrProgressBar As Object) Public Sub ChangeProgressBar(ByVal NbMaxEtape As Long, ByVal nEtapeExecuter As Integer, ByVal percent As Integer, ByVal CurrLabel As Object, ByVal CurrProgressBar As Object) If (Me.InvokeRequired) Then Dim vChangeProgressBar As New ChangeTextsProgressBar1Delegate(AddressOf ChangeProgressBar) Me.Invoke(vChangeProgressBar) Else CurrProgressBar.Value = percent CurrLabel.Text = percent & "%" Application.DoEvents() End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim percent As Short Dim nEtapeExecuter As Integer = 1 Dim NbMaxEtape As Integer = 4 Dim ProgressBarFormSplashScreenDelegate As New DelegateProgressBarFormSplashScreen(AddressOf ChangeProgressBar) percent = (nEtapeExecuter / NbMaxEtape) * 100 FonctionEtape1() Me.Invoke(ProgressBarFormSplashScreenDelegate, NbMaxEtape, nEtapeExecuter, percent, Label1, ProgressBar1) nEtapeExecuter += 1 percent = (nEtapeExecuter / NbMaxEtape) * 100 FonctionEtape2() Me.Invoke(ProgressBarFormSplashScreenDelegate, NbMaxEtape, nEtapeExecuter, percent, Label1, ProgressBar1) nEtapeExecuter += 1 percent = (nEtapeExecuter / NbMaxEtape) * 100 FonctionEtape3() Me.Invoke(ProgressBarFormSplashScreenDelegate, NbMaxEtape, nEtapeExecuter, percent, Label1, ProgressBar1) nEtapeExecuter += 1 percent = (nEtapeExecuter / NbMaxEtape) * 100 FonctionEtape4() Me.Invoke(ProgressBarFormSplashScreenDelegate, NbMaxEtape, nEtapeExecuter, percent, Label1, ProgressBar1) nEtapeExecuter += 1 Me.Invoke(ProgressBarFormSplashScreenDelegate, 0, 0, 0, Label1, ProgressBar1) 'Fin du processus End Sub