IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Variable à valeur croissante. [Débutant]


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Collégien
    Inscrit en
    Septembre 2011
    Messages
    113
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Collégien

    Informations forums :
    Inscription : Septembre 2011
    Messages : 113
    Par défaut Variable à valeur croissante.
    Bonjour.

    Me revoilà, depuis quelques temps je cherche à faire un programme permettant de télécharger des fichiers en masse, nommés numériquement, exemple :
    http://dl.google.com/1.swf
    http://dl.google.com/2.swf
    http://dl.google.com/500.swf

    bref, je sais comment télécharger, mais je ne sais pas comment faire pour que ma variable string ou integer, ait une valeur qui change après chaque téléchargements.
    Une aide me serait utile, cordialement.

  2. #2
    Membre confirmé
    Homme Profil pro
    Developpeur .Net
    Inscrit en
    Mai 2011
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Israël

    Informations professionnelles :
    Activité : Developpeur .Net
    Secteur : Service public

    Informations forums :
    Inscription : Mai 2011
    Messages : 32
    Par défaut Variable à valeur croissante
    Je ne sais pas si j'ai bien compris mais essayez ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     static int counter = 1
     
    public void Telecharger(string path)
    {
       string downloadedUrl = path +counter +".swf";
       counter++;
    }

  3. #3
    Invité
    Invité(e)
    Par défaut
    Salut,

    Tout dépendra du fait que tu ais un event qui te permet de savoir si un téléchargement est terminé. Si oui alors il suffit de gérer cet event.

  4. #4
    Membre confirmé
    Homme Profil pro
    Collégien
    Inscrit en
    Septembre 2011
    Messages
    113
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Collégien

    Informations forums :
    Inscription : Septembre 2011
    Messages : 113
    Par défaut
    Voici mon code
    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
    public partial class Form1 : Form
        {
            WebClient Client = new WebClient();
            static int swf = 0;
            public Form1()
            {
                InitializeComponent();
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
                string _url = "dl.google.com/1.swf";
                Client.DownloadFileAsync(new Uri(_url), "C:/Program Files (x86)");
            }
            void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
            {
                progressBar1.Maximum = (int)e.TotalBytesToReceive;
                progressBar1.Value = (int)e.BytesReceived;
            }
        }
    Toute optimisation, tout conseil ou question à propos de mon code sont les bienvenus.

  5. #5
    Invité
    Invité(e)
    Par défaut
    Je n'ai pas testé
    Code C# : 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
     
    private List<string> Paths; // À initialiser quelque part
    private void download(string path)
            {
                Client.DownloadFileAsync(new Uri(path), "C:/Program Files (x86)");
            }
    private void button1_Click(object sender, EventArgs e)
            {
                download(this.Paths[0]);
            }
            void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
            {
                progressBar1.Maximum = (int)e.TotalBytesToReceive;
                progressBar1.Value = (int)e.BytesReceived;
                if((int)e.TotalBytesToReceive == (int)e.BytesReceived)
               {
                     // on passe au suivant si la liste n'est pas vide
                     this.Paths.Remove(0);
                     if(this.Paths.Count != 0)
                         download(this.Paths[0]);
                }
            }

  6. #6
    Membre confirmé
    Homme Profil pro
    Collégien
    Inscrit en
    Septembre 2011
    Messages
    113
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Collégien

    Informations forums :
    Inscription : Septembre 2011
    Messages : 113
    Par défaut
    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
    private List<string> Paths; // À initialiser quelque part
    private void download(string path)
            {
                Client.DownloadFileAsync(new Uri(path), "C:/Program Files (x86)");
            }
    private void button1_Click(object sender, EventArgs e)
            {
                download(this.Paths[0]);
            }
            void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
            {
                progressBar1.Maximum = (int)e.TotalBytesToReceive;
                progressBar1.Value = (int)e.BytesReceived;
                if((int)e.TotalBytesToReceive == (int)e.BytesReceived)
               {
                     // on passe au suivant si la liste n'est pas vide
                     this.Paths.Remove(0);
                     if(this.Paths.Count != 0)
                         download(this.Paths[0]);
                }
            }
    Alors, je n'ai jamais utiliser de >> private List<string> Paths;
    pourrais-tu m'expliquer comment déclaré son contenue ? Merci.

  7. #7
    Membre confirmé
    Homme Profil pro
    Collégien
    Inscrit en
    Septembre 2011
    Messages
    113
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Collégien

    Informations forums :
    Inscription : Septembre 2011
    Messages : 113
    Par défaut
    Je poste la solution :
    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
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    using System.IO;
     
     
    namespace Downloader
    {
        public partial class Form1 : Form
        {
            static int swf = 1;
     
            public Form1()
            {
                InitializeComponent();
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
                while (swf < 100)
                {
                    try
                    {
                        WebClient Client = new WebClient();
                        Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(Client_DownloadProgressChanged);
                        string url = @"http://dl.google.com/" + swf + ".swf";
                        if (!File.Exists(@"swf/" + swf + ".swf"))
                        {
                            break;
                        }
                        else
                        {
                            Client.DownloadFileAsync(new Uri(url), @"swf/" + swf + ".swf");
                            swf++;
                        }
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("erreur " + error);
                    }
                }
                MessageBox.Show("fini", "Fini!");
            }
     
            void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
            {
                progressBar1.Maximum = (int)e.TotalBytesToReceive;
                progressBar1.Value = (int)e.BytesReceived;
            }
        }
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Fichier Variable = Valeur : Saisie sécurisée
    Par SRT__ dans le forum Général Python
    Réponses: 2
    Dernier message: 20/09/2007, 01h32
  2. [Variable]valeur maximale d'un integer
    Par nejisama8 dans le forum VBA Access
    Réponses: 2
    Dernier message: 24/04/2007, 17h08
  3. Réponses: 8
    Dernier message: 09/11/2006, 15h01
  4. Réponses: 7
    Dernier message: 11/02/2006, 01h05
  5. [VB6] Variable = Valeur d'une requete Select
    Par bb62 dans le forum VB 6 et antérieur
    Réponses: 11
    Dernier message: 23/01/2006, 15h40

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo