Dim F As StreamReader = New StreamReader("Version.txt", IO.FileMode.Open) Dim ligne As String Dim last_ligne As String Do last_ligne = ligne ligne = F.ReadLine() Loop Until ligne Is Nothing
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub Download_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Client As WebClient = New WebClient AddHandler Client.DownloadProgressChanged, AddressOf client_ProgressChanged AddHandler Client.DownloadFileCompleted, AddressOf client_DownloadCompleted Client.DownloadFileAsync(New Uri("URL à Télécharger"), "Test.exe") End Sub Private Sub client_ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) ProgressBar1.Value = e.ProgressPercentage Label1.Text = "Téléchargement de : . / " + e.ProgressPercentage.ToString + "%" End Sub
Mais je bloque toujours sur le téléchargement par ligne ...
Dim Nbr_Ligne As Integer Nbr_Ligne = 0 Dim F As StreamReader = New StreamReader("Version.txt", IO.FileMode.Open) Dim ligne As String Nbr_Ligne = 0 Do ligne = F.ReadLine() If Nbr_Ligne <> 0 Then MsgBox(ligne) End If Nbr_Ligne += 1 Loop Until ligne Is Nothing
Public list_download As List(Of String)
Dim Nbr_Ligne As Integer Nbr_Ligne = 0 Dim F As StreamReader = New StreamReader("Version.txt", IO.FileMode.Open) Dim ligne As String Nbr_Ligne = 0 Do ligne = F.ReadLine() If Nbr_Ligne <> 0 Then list_download.Add(ligne) MsgBox(ligne) End If Nbr_Ligne += 1 Loop Until ligne Is Nothing
Private Sub client_DownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) ' Je vérifie si le tableau est vide. If list_download.Any Then ' S'il l'est pas, je retire la première ligne. ( Téléchargement déjà fait. ) list_download.RemoveAt(0) ' Et je relance un téléchargement Else ' Je "ferme" la fenêtre quand tout les téléchargements sont finit. MessageBox.Show("Téléchargement Terminé !") ActiveForm.Close() Index.Show() Index.Enabled = True Index.Activate() End If End Sub
Mais bizarrement, la boucle ne se fait jamais ...
Dim list_download As New List(Of String) Using reader As New IO.StreamReader("version.txt") Dim version As String = reader.ReadLine If version <> version_actuelle Then Do While Not reader.EndOfStream list_download.Add(reader.ReadLine) Loop End If End Using
Imports System Imports System.Net Imports System.Text Imports System.IO Imports System.IO.File Public Class FoA Public list_download As List(Of String) = New List(Of String) Private Sub client_ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) ProgressBar1.Value = e.ProgressPercentage Dim Name ' Si la liste est pas vide, je recupère le premier élément, je recupère juste la fin, et change mon label pour afficher le nom et le %age. ' Mais il me dit que la liste est toujours vide ( Rien ne change ). If list_download.Count <> 0 Then Name = Split(MsgBox(list_download.First), "http://caelondia.voila.net/") Label1.Text = "Téléchargement de : " + Name(1) + " / " + e.ProgressPercentage.ToString + "%" End If End Sub Private Sub client_DownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) MsgBox(list_download.Count) 'Me renvoie 0. If list_download.Count <> 0 Then ' Si c'est pas vide, je relance le prochain DL. ' Il manque surement un truc pour retirer le premier élément de la liste, mais pour l'instant, le reste marche pas alors ... Dim Name Name = Split(list_download.First, "http://caelondia.voila.net/") Dim Client As WebClient = New WebClient AddHandler Client.DownloadProgressChanged, AddressOf client_ProgressChanged AddHandler Client.DownloadFileCompleted, AddressOf client_DownloadCompleted Client.DownloadFileAsync(New Uri(list_download.ElementAt(0)), Name(1)) Else ' Affiche la fin du DL. MessageBox.Show("Téléchargement Terminé !") End If End Sub Private Sub Download_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Lorsque la fenêtre s'ouvre. Dim Name Dim n As String Dim Nbr_Ligne As Integer Nbr_Ligne = 0 ' La boucle pour recupèrer les liens. Dim list_download As New List(Of String) Using reader As New IO.StreamReader("Version.txt") Dim version As String = reader.ReadLine Do While Not reader.EndOfStream n = reader.ReadLine list_download.Add(n) ' Ajoute le lien à la liste Loop End Using MsgBox(list_download.Count) ' Affiche bien 2. Name = Split(list_download.First, "http://caelondia.voila.net/") ' Recupère le nom du fichier. Dim Client As WebClient = New WebClient AddHandler Client.DownloadProgressChanged, AddressOf client_ProgressChanged AddHandler Client.DownloadFileCompleted, AddressOf client_DownloadCompleted Client.DownloadFileAsync(New Uri(list_download.First), Name(1)) ' Lance le DL. MsgBox(list_download.Count) ' Retourne bien 2. End Sub End Class
Dim list_download As New List(Of String)
ActiveForm.Enabled = False ' La fenêtre actuelle devient "inclicable" Download.Show() ' J'affiche la fenêtre de DL.
Private Sub Form2_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.GotFocus If ActiveForm.Enabled = False Then MsgBox("Aze") Download.Focus() End If End Sub