''index pour sauvegarde journalière If ComboBox1.SelectedIndex = 2 Then If Date.Now.Hour.ToString DateTimePicker1.Text Or Date.Now.Minute.ToString DateTimePicker2.Text Then copie() End If End If
If ComboBox1.SelectedIndex = 2 Then If prochaine_copie Date.Now.Day And Date.Now.Hour.ToString DateTimePicker1.Text And Date.Now.Minute.ToString = DateTimePicker2.Text Then copie() prochaine_copie = Date.Now.Day + 1 End If End If
prochaine_copie = Date.Now.Day
Dim prochaine_copie As Integer
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionIf ComboBox1.SelectedIndex = 2 Then If prochaine_copie Date.Now.Day And Date.Now.Hour.ToString DateTimePicker1.Text And Date.Now.Minute.ToString = DateTimePicker2.Text Then copie() prochaine_copie = Date.Now.Day + 1 End If End If If ComboBox1.SelectedIndex = 1 Then If prochaine_copie 1 Or prochaine_copie 8 Or prochaine_copie = 15 Or prochaine_copie = 22 Or prochaine_copie = 29 And Date.Now.Hour.ToString = DateTimePicker1.Text And Date.Now.Minute.ToString = DateTimePicker2.Text Then copie() End If End If If ComboBox1.SelectedIndex = 0 Then If Date.Now.Hour.ToString DateTimePicker1.ToString And prochaine_copie 1 And Date.Now.Minute.ToString = DateTimePicker2.ToString Then copie() End If End If
If prochaine_copie Date.Now.Day And Date.Now.Hour.ToString DateTimePicker1.Text And Date.Now.Minute.ToString = DateTimePicker2.Text Then
Pour connaitre l'emplacement de ton exe :
http://msdn.microsoft.com/en-us/library/aa457089.aspx
Dim da As Date Dim prochainnum As Integer da = DateTimePicker1.Value If (prochainnum Date.Now.Day) And (Date.Now.Hour da.Hour) And (Date.Now.Minute = da.Minute) Then End If
Public Class Form1 Dim nbfic As Integer Dim Chem_Rep_src As String Dim Chem_Rep_dest As String Dim ladate As String Dim prochaine_copie As Integer Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing If CheckBox1.CheckState = CheckState.Checked Then SaveSetting("Sauvegarde", "Startup", "heure", DateTimePicker1.Value) SaveSetting("Sauvegarde", "Startup", "minute", DateTimePicker2.Value) SaveSetting("Sauvegarde", "Startup", "frequence", ComboBox1.SelectedItem.ToString) SaveSetting("Sauvegarde", "Startup", "checkbox", "1") Else SaveSetting("Sauvegarde", "Startup", "heure", Date.Now.ToString) SaveSetting("Sauvegarde", "Startup", "minute", Date.Now.ToString) SaveSetting("Sauvegarde", "Startup", "frequence", ComboBox1.SelectedIndex = 2) SaveSetting("Sauvegarde", "Startup", "checkbox", "0") End If NotifyIcon1.Visible = False End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load prochaine_copie = Date.Now.Day NotifyIcon1.ContextMenuStrip = ContextMenuStrip1 '// attach ContextMenu to NotifyIcon. TextBox1.Text = "Chemin non définit" TextBox2.Text = "Chemin non définit" Label5.Text = "-" Label7.Text = "" Label12.Text = "-" If Not Dir("file2data.exe", vbNormal) = "" Then MsgBox("Le fichier FIC vers MDB doit se trouver dans le dossier file2data") Me.Close() End If ComboBox1.Items.Add("Mensuel") ComboBox1.Items.Add("Hebdomadaire") ComboBox1.Items.Add("Journalier") ComboBox1.SelectedIndex = 2 SetMyCustomFormat() DateTimePicker1.Value = GetSetting("Sauvegarde", "Startup", "heure", "") DateTimePicker2.Value = GetSetting("Sauvegarde", "Startup", "minute", "") ComboBox1.SelectedItem = GetSetting("Sauvegarde", "Startup", "frequence", "") If GetSetting("Sauvegarde", "Startup", "checkbox", "1") Then CheckBox1.CheckState = CheckState.Checked Else CheckBox1.CheckState = CheckState.Unchecked End If End Sub Private Sub NotifyIcon1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseClick If e.Button = MouseButtons.Right Then NotifyIcon1.ContextMenuStrip.Show() '// Show ContextMenu on Right Mouse click. End Sub Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick Me.Show() Me.WindowState = FormWindowState.Normal Me.Activate() Me.Focus() End Sub Public Sub SetMyCustomFormat() ' Set the Format type and the CustomFormat string. DateTimePicker1.Format = DateTimePickerFormat.Custom DateTimePicker1.CustomFormat = "HH" DateTimePicker2.Format = DateTimePickerFormat.Custom DateTimePicker2.CustomFormat = "mm" End Sub Private Sub B_parcourir_in_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_parcourir_in.Click FolderBrowserDialog1.ShowDialog() If Not FolderBrowserDialog1.SelectedPath = Nothing Then TextBox1.Text = FolderBrowserDialog1.SelectedPath.ToString Chem_Rep_src = FolderBrowserDialog1.SelectedPath.ToString & "" Label5.Text = CompterFichiers(FolderBrowserDialog1.SelectedPath.ToString, "*.FIC") nbfic = Label5.Text End If End Sub Public Function CompterFichiers(ByRef vsFolder As String, ByRef vsPattern As String) As Integer Return My.Computer.FileSystem.GetFiles(vsFolder, FileIO.SearchOption.SearchTopLevelOnly, vsPattern).Count End Function Private Sub B_parcourir_out_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_parcourir_out.Click FolderBrowserDialog2.ShowDialog() If Not FolderBrowserDialog2.SelectedPath = Nothing Then TextBox2.Text = FolderBrowserDialog2.SelectedPath.ToString Chem_Rep_dest = FolderBrowserDialog2.SelectedPath.ToString & "" End If End Sub Private Sub B_convertir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_convertir.Click copie() End Sub Public Sub copie() Dim fichiersTrouves As String If TextBox1.Text = "Chemin non définit" Then MsgBox("Veuillez rentrer un dossier source") Else If TextBox2.Text = "Chemin non définit" Then MsgBox("Veuillez rentrer un dossier de destination") Else ' On fixe la valeur minimale de la ProgressBar ProgressBar1.Minimum = 0 ' On fixe la valeur maximale de la ProgressBar ' le nombre de fichiers à copier donc ProgressBar1.Maximum = My.Computer.FileSystem.GetFiles(Chem_Rep_src, Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, "*.bat", "*.txt", "*.exe").Count ' On fixe sa valeur actuelle à 0 ProgressBar1.Value = 0 ' On fixe le pas de la ProgressBar ' c'est la valeur qui va être ajouter ' à Value dés qu'on utilise PerformStep ProgressBar1.Step = 1 'Récupère les fichiers du dossier source et leurs extensions. For Each fichiersTrouves In My.Computer.FileSystem.GetFiles(Chem_Rep_src, Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, "*.bat", "*.txt", "*.exe") 'copie des fichiers vers le dossier de destination. Si les mêmes fichiers sont présent il les écrasent. My.Computer.FileSystem.CopyFile(fichiersTrouves, Chem_Rep_dest & My.Computer.FileSystem.GetName(fichiersTrouves), True) ' la quantité spécifiée par Step ProgressBar1.PerformStep() Next Label7.Text = "terminé" Label12.Text = Date.Now Timer2.Enabled = True End If End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If ComboBox1.SelectedIndex = 2 Then If prochaine_copie Date.Now.Day And Date.Now.Hour.ToString DateTimePicker1.Text And Date.Now.Minute.ToString = DateTimePicker2.Text Then copie() prochaine_copie = Date.Now.Day + 1 End If End If If ComboBox1.SelectedIndex = 1 Then If prochaine_copie 1 Or prochaine_copie 8 Or prochaine_copie = 15 Or prochaine_copie = 22 Or prochaine_copie = 29 And Date.Now.Hour.ToString = DateTimePicker1.Text And Date.Now.Minute.ToString = DateTimePicker2.Text Then copie() prochaine_copie = Date.Now.Day + 1 End If End If If ComboBox1.SelectedIndex = 0 Then If Date.Now.Hour.ToString DateTimePicker1.ToString And prochaine_copie 1 And Date.Now.Minute.ToString = DateTimePicker2.ToString Then copie() prochaine_copie = Date.Now.Day + 1 End If End If End Sub Private Sub FermerToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FermerToolStripMenuItem.Click Me.Close() End Sub Private Sub OuvrirToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OuvrirToolStripMenuItem.Click Me.Show() Me.WindowState = FormWindowState.Normal Me.Activate() Me.Focus() End Sub Private Sub B_sauvegarde_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_sauvegarde.Click If TextBox1.Text = "Chemin non définit" Then MsgBox("Veuillez rentrer un dossier source") Else If TextBox2.Text = "Chemin non définit" Then MsgBox("Veuillez rentrer un dossier de destination") Else If B_sauvegarde.Text = "activé" Then Timer1.Enabled = False B_sauvegarde.Text = "désactivé" B_sauvegarde.ForeColor = Color.Red ComboBox1.Enabled = True Else Timer1.Enabled = True B_sauvegarde.Text = "activé" B_sauvegarde.ForeColor = Color.Green ComboBox1.Enabled = False End If End If End If End Sub Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick ProgressBar1.Value = 0 Label7.Text = "" Timer2.Enabled = False End Sub End Class
If prochaine_copie = Date.Now.Day And Date.Now.Hour.ToString = DateTimePicker1.Text And Date.Now.Minute.ToString = DateTimePicker2.Text
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim da As Date da = DateTimePicker1.Value If ComboBox1.SelectedIndex = 2 Then If prochaine_copie Date.Now.Day) And (Date.Now.Hour da.Hour) And (Date.Now.Minute = da.Minute) Then 'pareil pour les autres if
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim da1 As Date Dim da2 As Date da1 = DateTimePicker1.Value da2 = DateTimePicker2.Value If ComboBox1.SelectedIndex = 2 Then If prochaine_copie Date.Now.Day And Date.Now.Hour.ToString da1.Hour And Date.Now.Minute.ToString = da2.Minute Then copie() prochaine_copie = Date.Now.Day + 1 End If End If If ComboBox1.SelectedIndex = 1 Then If prochaine_copie 1 Or prochaine_copie 8 Or prochaine_copie = 15 Or prochaine_copie = 22 Or prochaine_copie = 29 And Date.Now.Hour.ToString = da1.Hour And Date.Now.Minute.ToString = da2.Minute Then copie() prochaine_copie = Date.Now.Day + 1 End If End If If ComboBox1.SelectedIndex = 0 Then If Date.Now.Hour.ToString da1.Hour And prochaine_copie 1 And Date.Now.Minute.ToString = da2.Minute Then copie() prochaine_copie = Date.Now.Day + 1 End If End If End Sub
DateTimePicker1.value.hour- l'heure
DateTimePicker1.value.minute- la minute
Try 'Récupère les fichiers du dossier source et leurs extensions. For Each fichiersTrouves In My.Computer.FileSystem.GetFiles(Chem_Rep_src, Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, "*.bat", "*.txt", "*.exe") 'copie des fichiers vers le dossier de destination. Si les mêmes fichiers sont présent il les écrasent. My.Computer.FileSystem.CopyFile(fichiersTrouves, Chem_Rep_dest & My.Computer.FileSystem.GetName(fichiersTrouves), True) ' la quantité spécifiée par Step ProgressBar1.PerformStep() Next Catch ex As Exception MessageBox.Show(ex.Message) End Try
'ajoute dans le fichier historique.txt les heures et la date des sauvegardes. Si le fichier n'existe pas il est créé sinon c'est ajouté à la ligne suivante. File.AppendAllText(Application.StartupPath & "\historique.txt", Date.Now & Environment.NewLine)
Imports System.IO Public Class Form1 Dim nbfic, prochaine_copie As Integer Dim Chem_Rep_src, Chem_Rep_dest As String Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing If CheckBox1.CheckState = CheckState.Checked Then SaveSetting("Sauvegarde", "Startup", "heure", DateTimePicker1.Value) SaveSetting("Sauvegarde", "Startup", "minute", DateTimePicker2.Value) SaveSetting("Sauvegarde", "Startup", "frequence", ComboBox1.SelectedItem.ToString) SaveSetting("Sauvegarde", "Startup", "checkbox", "1") SaveSetting("Sauvegarde", "Startup", "dossier_src", TextBox1.Text) SaveSetting("Sauvegarde", "Startup", "dossier_dest", TextBox2.Text) Else SaveSetting("Sauvegarde", "Startup", "frequence", ComboBox1.SelectedIndex = 2) SaveSetting("Sauvegarde", "Startup", "checkbox", "0") End If NotifyIcon1.Visible = False End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load prochaine_copie = Date.Now.Day NotifyIcon1.ContextMenuStrip = ContextMenuStrip1 '// attach ContextMenu to NotifyIcon. TextBox1.Text = "Chemin non définit" TextBox2.Text = "Chemin non définit" Label5.Text = "-" Label7.Text = "" Label12.Text = "-" If Not Dir("file2data.exe", vbNormal) = "" Then MsgBox("Le fichier FIC vers MDB doit se trouver dans le dossier file2data") Me.Close() End If ComboBox1.Items.Add("Mensuel") ComboBox1.Items.Add("Hebdomadaire") ComboBox1.Items.Add("Journalier") ComboBox1.SelectedIndex = 2 SetMyCustomFormat() ComboBox1.SelectedItem = GetSetting("Sauvegarde", "Startup", "frequence", "") If GetSetting("Sauvegarde", "Startup", "checkbox", "") = 1 Then CheckBox1.CheckState = CheckState.Checked DateTimePicker1.Value = GetSetting("Sauvegarde", "Startup", "heure", "") DateTimePicker2.Value = GetSetting("Sauvegarde", "Startup", "minute", "") Chem_Rep_src = GetSetting("Sauvegarde", "Startup", "dossier_src", "") Chem_Rep_dest = GetSetting("Sauvegarde", "Startup", "dossier_dest", "") TextBox1.Text = Chem_Rep_src TextBox2.Text = Chem_Rep_dest Else CheckBox1.CheckState = CheckState.Unchecked DateTimePicker1.Value = Date.Now.ToString DateTimePicker2.Value = Date.Now.ToString End If End Sub Private Sub NotifyIcon1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseClick If e.Button = MouseButtons.Right Then NotifyIcon1.ContextMenuStrip.Show() '// Show ContextMenu on Right Mouse click. End Sub Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick Me.Show() Me.WindowState = FormWindowState.Normal Me.Activate() Me.Focus() End Sub Public Sub SetMyCustomFormat() ' Set the Format type and the CustomFormat string. DateTimePicker1.Format = DateTimePickerFormat.Custom DateTimePicker1.CustomFormat = "HH" DateTimePicker2.Format = DateTimePickerFormat.Custom DateTimePicker2.CustomFormat = "mm" End Sub Private Sub B_parcourir_in_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_parcourir_in.Click FolderBrowserDialog1.ShowDialog() If Not FolderBrowserDialog1.SelectedPath = Nothing Then TextBox1.Text = FolderBrowserDialog1.SelectedPath.ToString Chem_Rep_src = FolderBrowserDialog1.SelectedPath.ToString & "" Label5.Text = CompterFichiers(FolderBrowserDialog1.SelectedPath.ToString, "*.FIC") nbfic = Label5.Text End If End Sub Public Function CompterFichiers(ByRef vsFolder As String, ByRef vsPattern As String) As Integer Return My.Computer.FileSystem.GetFiles(vsFolder, FileIO.SearchOption.SearchTopLevelOnly, vsPattern).Count End Function Private Sub B_parcourir_out_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_parcourir_out.Click FolderBrowserDialog2.ShowDialog() If Not FolderBrowserDialog2.SelectedPath = Nothing Then TextBox2.Text = FolderBrowserDialog2.SelectedPath.ToString Chem_Rep_dest = FolderBrowserDialog2.SelectedPath.ToString & "" End If End Sub Private Sub B_convertir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_convertir.Click copie() End Sub Public Sub copie() Dim fichiersTrouves As String If TextBox1.Text = "Chemin non définit" Then MsgBox("Veuillez rentrer un dossier source") Else If TextBox2.Text = "Chemin non définit" Then MsgBox("Veuillez rentrer un dossier de destination") Else ' On fixe la valeur minimale de la ProgressBar ProgressBar1.Minimum = 0 ' On fixe la valeur maximale de la ProgressBar ' le nombre de fichiers à copier donc ProgressBar1.Maximum = My.Computer.FileSystem.GetFiles(Chem_Rep_src, Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, "*.bat", "*.txt", "*.exe").Count ' On fixe sa valeur actuelle à 0 ProgressBar1.Value = 0 ' On fixe le pas de la ProgressBar ' c'est la valeur qui va être ajouter ' à Value dés qu'on utilise PerformStep ProgressBar1.Step = 1 Try 'Récupère les fichiers du dossier source et leurs extensions. For Each fichiersTrouves In My.Computer.FileSystem.GetFiles(Chem_Rep_src, Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, "*.bat", "*.txt", "*.exe") 'copie des fichiers vers le dossier de destination. Si les mêmes fichiers sont présent il les écrasent. My.Computer.FileSystem.CopyFile(fichiersTrouves, Chem_Rep_dest & My.Computer.FileSystem.GetName(fichiersTrouves), True) ' la quantité spécifiée par Step ProgressBar1.PerformStep() Next Label7.Text = "terminé" Label12.Text = Date.Now Timer2.Enabled = True 'ajoute dans le fichier historique.txt les heures et la date des sauvegardes. Si le fichier n'existe pas il est créé sinon c'est ajouté à la ligne suivante. File.AppendAllText(Application.StartupPath & "\historique.txt", Date.Now & Environment.NewLine) Catch ex As Exception MessageBox.Show(ex.Message) End Try End If End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim da1, da2 As Date da1 = DateTimePicker1.Value da2 = DateTimePicker2.Value If ComboBox1.SelectedIndex = 2 Then If prochaine_copie Date.Now.Day And Date.Now.Hour.ToString da1.Hour And Date.Now.Minute.ToString = da2.Minute Then copie() prochaine_copie = Date.Now.Day + 1 End If End If If ComboBox1.SelectedIndex = 1 Then If prochaine_copie 1 Or prochaine_copie 8 Or prochaine_copie = 15 Or prochaine_copie = 22 Or prochaine_copie = 29 And Date.Now.Hour.ToString = da1.Hour And Date.Now.Minute.ToString = da2.Minute Then copie() prochaine_copie = Date.Now.Day + 1 End If End If If ComboBox1.SelectedIndex = 0 Then If Date.Now.Hour.ToString da1.Hour And prochaine_copie 1 And Date.Now.Minute.ToString = da2.Minute Then copie() prochaine_copie = Date.Now.Day + 1 End If End If End Sub Private Sub FermerToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FermerToolStripMenuItem.Click Me.Close() End Sub Private Sub OuvrirToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OuvrirToolStripMenuItem.Click Me.Show() Me.WindowState = FormWindowState.Normal Me.Activate() Me.Focus() End Sub Private Sub B_sauvegarde_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_sauvegarde.Click If TextBox1.Text = "Chemin non définit" Then MsgBox("Veuillez rentrer un dossier source") Else If TextBox2.Text = "Chemin non définit" Then MsgBox("Veuillez rentrer un dossier de destination") Else If B_sauvegarde.Text = "activé" Then Timer1.Enabled = False B_sauvegarde.Text = "désactivé" B_sauvegarde.ForeColor = Color.Red ComboBox1.Enabled = True Else Timer1.Enabled = True B_sauvegarde.Text = "activé" B_sauvegarde.ForeColor = Color.Green ComboBox1.Enabled = False End If End If End If End Sub Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick ProgressBar1.Value = 0 Label7.Text = "" Timer2.Enabled = False End Sub End Class