[VB.NET] Comment créer un chromètre
BobyCode
Messages postés
9
Statut
Membre
-
BobyCode Messages postés 9 Statut Membre -
BobyCode Messages postés 9 Statut Membre -
Bonjour,
Alors voilà, je voudrais créer un chronomètre et un temps restant (comme quand vous télécharger quelques chose sur votre navigateur). J'utilise Timer pour cela mais j'ai un problème quand je lance le Timer dans ma fonction, il ne se lance pas alors que dans le Form_load ça marche.
Voici mon code :
Merci :)
Alors voilà, je voudrais créer un chronomètre et un temps restant (comme quand vous télécharger quelques chose sur votre navigateur). J'utilise Timer pour cela mais j'ai un problème quand je lance le Timer dans ma fonction, il ne se lance pas alors que dans le Form_load ça marche.
Voici mon code :
Private Sub ExcelExtract(ByVal chemin As String)
LabelX1.Text = "Initialisation du fichier..."
LabelX2.Visible = True
Cursor = Cursors.WaitCursor
ProgressBarX1.Value = 0
'Excel
'Définition des variables
Dim xlApp As Application
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xl1 As Microsoft.Office.Interop.Excel.Worksheet
' nettoyage des tables temporaires avant importation des données
ExecuteSql("DELETE FROM poste")
ExecuteSql("ALTER TABLE poste AUTO_INCREMENT=1")
'Code
xlApp = New Microsoft.Office.Interop.Excel.Application
xlWorkBook = xlApp.Workbooks.Open(chemin)
xl1 = xlWorkBook.Worksheets(1)
'Définition des mois
moisDebut = ComboBoxEx1.Text
moisFin = ComboBoxEx3.Items(ComboBoxEx3.SelectedIndex + 1).text
'Initialisation, définir les colonnes et les lignes
Dim firstLigne As Integer = 1
Dim firstColumn As Integer
Dim lastLigne As Integer = xl1.Cells.SpecialCells(XlCellType.xlCellTypeLastCell).Row
Dim lastColumnAll As Integer = xl1.Cells.SpecialCells(XlCellType.xlCellTypeLastCell).Column
Dim lastColumn As Integer
Dim columnPostes As Integer
Dim columnMachines As Integer = 1
Dim columnEquipe As Integer
Dim ligneMois As Integer
Dim ligneJour As Integer
Dim nomMachine As String = ""
'Définiton des variables colonnes et lignes
Dim quitter As Integer = 0
For j As Integer = 1 To lastColumnAll
For i As Integer = 1 To lastLigne
If xl1.Cells(i, j).text = "JANVIER" Then
Dim quitterMois As Integer = 0
For l As Integer = j To lastColumnAll
If xl1.Cells(i, l).text = moisDebut Then
ligneMois = i
firstColumn = l
ligneJour = ligneMois + 3
quitter += 1
quitterMois += 1
ElseIf xl1.Cells(i, l).text = moisFin Then
lastColumn = l - 1
quitter += 1
quitterMois += 1
End If
If quitterMois = 2 Then Exit For
Next
ElseIf xl1.Cells(i, j).text = "Postes" Then
columnPostes = j
quitter += 1
ElseIf xl1.Cells(i, j).text = "Equipe" Then
If columnEquipe <> j Then
columnEquipe = j
quitter += 1
End If
End If
If quitter = 4 Then Exit For
Next
If quitter = 4 Then Exit For
Next
LabelX1.Text = "Extraction des données... (Cette opération peut prendre quelques minutes)"
For i As Integer = firstLigne To lastLigne 'Lignes du tableau
ProgressBarX1.Value = i * 100 / (lastLigne - firstLigne)
LabelX2.Text = "" & Math.Round((i * 100 / (lastLigne - firstLigne)), 0) & " %"
If xl1.Cells(i, columnMachines).value <> "" Then
nomMachine = xl1.Cells(i, columnMachines).value
For j As Integer = 0 To 2
For col As Integer = firstColumn To lastColumn 'Colonnes du tableau
If xl1.Cells(i + j, col).Interior.colorindex = 48 And xl1.Cells(i + j, col).value Is Nothing Then
'Trouver le mois
Dim words As String = xl1.Cells(ligneMois, col).MergeArea.Address.ToString()
Dim split As String() = words.Split(New [Char]() {":"c, CChar(vbTab)})
ExecuteSql("INSERT INTO poste(nomPoste, nomMachine,Equipe,date)" & _
"values('" & xl1.Cells(i, columnPostes).value & "'," & _
"'" & nomMachine & "'," & _
"'" & xl1.Cells(i + j, columnEquipe).value & "'," & _
"'" & xl1.Cells(ligneJour, col).value.ToString() & " " & xl1.Range("" & split(0) & "").Value & " 2014')")
End If
Next
Next
ElseIf xl1.Cells(i, columnPostes).value <> "" Then
For j As Integer = 0 To 2
For col As Integer = firstColumn To lastColumn 'Colonnes du tableau
If xl1.Cells(i + j, col).Interior.colorindex = 48 And xl1.Cells(i + j, col).value Is Nothing Then
Dim words As String = xl1.Cells(ligneMois, col).MergeArea.Address.ToString()
Dim split As String() = words.Split(New [Char]() {":"c, CChar(vbTab)})
ExecuteSql("INSERT INTO poste(nomPoste, nomMachine,Equipe,date)" & _
"values('" & xl1.Cells(i, columnPostes).value & "'," & _
"'" & nomMachine & "'," & _
"'" & xl1.Cells(i + j, columnEquipe).value & "'," & _
"'" & xl1.Cells(ligneJour, col).value.ToString() & " " & xl1.Range("" & split(0) & "").Value & " 2014')")
End If
Next
Next
Else
End If
Next
'Active app could change before this runs
xlWorkBook.Close(False)
xlWorkBook = Nothing
xlApp.Quit()
xlApp = Nothing
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
LabelX1.Text = "Success!"
ProgressBarX1.Value = 100
Cursor = Cursors.Default
ButtonX1.Visible = True
LabelX3.Visible = True
ProgressBarX2.Visible = True
End Sub
Merci :)
A voir également:
- [VB.NET] Comment créer un chromètre
- Comment créer un groupe whatsapp - Guide
- Créer un compte google - Guide
- Comment créer un compte gmail - Guide
- Créer un lien pour partager des photos - Guide
- Comment creer un organigramme - Guide
3 réponses
Bonjour,
C'est normal que le timer ne fonctionne pas pendant la durée de la tâche demandée. Il faut utiliser un thread qui agit en arrière plan. Voir ceci pour la mise en oeuvre d'un thread:
https://plasserre.developpez.com/cours/vb-net/?page=windows-forms5#LX-R
C'est normal que le timer ne fonctionne pas pendant la durée de la tâche demandée. Il faut utiliser un thread qui agit en arrière plan. Voir ceci pour la mise en oeuvre d'un thread:
https://plasserre.developpez.com/cours/vb-net/?page=windows-forms5#LX-R
Bonjour,
Si tu utilise Microsoft Visual Basic ou Visual Studio, le timer est généralement désactivé par défaut.
Pour l'activer, règle la propriété Enabled sur True

Si tu utilise Microsoft Visual Basic ou Visual Studio, le timer est généralement désactivé par défaut.
Pour l'activer, règle la propriété Enabled sur True

Tu rentre bien la fonction directement dans le timer (en double - cliquant dessus) ?
Par exemple :
Je m'y connais pas trop en Vb.net
Par exemple :
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim mavariable As Integer
mavariable = mavariable + 1
Label1.text = mavariable
End Sub
Je m'y connais pas trop en Vb.net
Merci !