Comment récupérer dans un listbox les traces du debug ?

Résolu
cs_fabiano13 Messages postés 262 Date d'inscription mardi 26 février 2002 Statut Membre Dernière intervention 27 février 2012 - 8 avril 2011 à 20:58
cs_fabiano13 Messages postés 262 Date d'inscription mardi 26 février 2002 Statut Membre Dernière intervention 27 février 2012 - 9 avril 2011 à 16:46
Bonsoir,

Comment récupérer dans un listbox le contenu des traces du debug ?

J'ai cherché partout mais je n'ai rien trouvé.

D'avance merci pour votre aide.

Fabiano

9 réponses

cs_fabiano13 Messages postés 262 Date d'inscription mardi 26 février 2002 Statut Membre Dernière intervention 27 février 2012
9 avril 2011 à 16:46
J'ai trouvé, encore merci pour l'aide que vous m'avez apporté tous les deux, voici une piste valable :

1) Form1 est le formulaire principal.
2) Form2 est le SplashScreen à l'init.
3) La fonction trace c'est juste une liste box qui me sert à récupérer du texte (pas obligatoire)

Le principe est là :



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


3
NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 159
8 avril 2011 à 22:22
Bonjour,

Les appels Debug.* ne sont pas (il me semble) compilé en mode Release, à toi de faire ton propre système.

Mon site
0
cs_fabiano13 Messages postés 262 Date d'inscription mardi 26 février 2002 Statut Membre Dernière intervention 27 février 2012
8 avril 2011 à 23:15
Merci de bien vouloir m'aider.

Je cherche à faire un splashscreen au démarrage de mon application (ça c'est simple). Seulement pour faire patienter, je cherche à lister tous les éléments du form comme celui du debug au lancement du debug.

Aurais-tu une piste ?

D'avance merci.
Fabiano
0
NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 159
8 avril 2011 à 23:52
Bonjour,

"Je cherche à faire un splashscreen au démarrage de mon application"
là ça va, c'est dans les options du projet pour faire l'affichage automatiquement. (il me semble)

"Seulement pour faire patienter, je cherche à lister tous les éléments du form comme celui du debug au lancement du debug. "
Alors, là, j'ai pas du tout compris.

Mon site
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_fabiano13 Messages postés 262 Date d'inscription mardi 26 février 2002 Statut Membre Dernière intervention 27 février 2012
9 avril 2011 à 03:17
J'ai cherché jusqu'à maintenant mais je n'ai rien trouvé !!

Ce que je souhaite faire c'est :
- soit faire une progressbar qui affiche le déroulement du chargement du form1 (principal)
- soit lister les événements du processus de démarrage du form1 (thread, load dll...) .

Car l'application principale est longue à s'ouvrir, il y a dans le Form_Load plusieurs fonctions lourdes à charger (connexion serveur, mise à jour des listes...)

Dans les deux cas je ne sais pas faire !

Pourrais-tu m'aider ?

D'avance merci.
Fabiano
0
Calade Messages postés 1207 Date d'inscription dimanche 20 avril 2003 Statut Membre Dernière intervention 4 juin 2016 10
9 avril 2011 à 13:39
Bonjour,

Je m'étais heurté au même problème pour une appli en VB6. Bon ce n'était que VB6, mais je ne vois pas comment on pourrait récupérer les "étapes" de chargement qui se font toutes en tâche de fond.

Je vois 2 possibilités:

1) Ce sont effectivement des tâches de fond entièrement géré par le système, auquel cas tu n'as aucune prise dessus. J'avais biaisé en faisant un petit GIF animé imitant une barre de progression. Ce n'est qu'un affichage qui ne prouve absolument pas que ton appli n'est pas planté, mais après tout Windows n'a jamais été capable de faire mieux !

2)Ce sont des tâches que tu lances toi-même, Connexion à la BDD, requêtes d'initialisation des recordsets..., là rien ne t'empêche de faire un affichage avant/après chaque évènement.

En espérant pouvoir t'aider.


Calade
0
cs_fabiano13 Messages postés 262 Date d'inscription mardi 26 février 2002 Statut Membre Dernière intervention 27 février 2012
9 avril 2011 à 14:36
Merci pour ta réponse.

Comment communiquer entre 2 forms ? Voici mon code, suite à ton conseil :


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 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

0
Calade Messages postés 1207 Date d'inscription dimanche 20 avril 2003 Statut Membre Dernière intervention 4 juin 2016 10
9 avril 2011 à 14:40
Désolé,

Je ne connais pas .NET, mais en VB6 on pouvait rendre Public une fonction située dans une Form.

Et dans cette fonction, tu peux très bien gérer l'affichage progressive de ta SplashScrreen.


Calade
0
cs_fabiano13 Messages postés 262 Date d'inscription mardi 26 février 2002 Statut Membre Dernière intervention 27 février 2012
9 avril 2011 à 14:45
Je vais essayer, je te tiens au courant.

Encore merci pour ton aide.
Fabiano
0
Rejoignez-nous