Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

[Problem] błąd kodu


Rekomendowane odpowiedzi

Opublikowano

mam kod

 

Imports System.Net
Imports System.ComponentModel
 
Public Class Form1
 
    Public WithEvents download As New WebClient
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
 
 
        If My.Computer.Network.IsAvailable Then
            Button1.Enabled = False
            My.Computer.FileSystem.CreateDirectory("/bartek")
            ProgressBar1.Visible = True
 
 
            download.DownloadFileAsync(New Uri("https://doc-0k-0g-docsviewer.googleusercontent.com/viewer/securedownload/7fk59m1egp6992didvvgpavtvdbvpg6d/jsqhm0rp62s9i4klrhorv0g2ru33lgte/1373181300000/ZXhwbG9yZXI=/AGZ5hq9ESxy8t5nop0m1WhLOrj6D/MEJ3MWYzb0hZZE0yblgyZEZkMk14ZDFkNk0yOA==?sec=AHSqidYv1OM2ql_CMY0b_q-0LqDg4BWQdvsEAi7M6uxz9-_BSICF29nBPng2nTqc5TH9w392Jyg9&a=dl&filename=MC.zip&rel=zip;z3;MC_Open_Launcher.jar&nonce=87a51vllrraac&user=AGZ5hq9ESxy8t5nop0m1WhLOrj6D&hash=ne3k23s86at3grfbrsu667anossf55ih"), "/bartek/lol.exe")
        Else
            MsgBox("Brak dostępu do Internetu")
        End If
 
    End Sub
 
    Private Sub download_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles download.DownloadProgressChanged
        ProgressBar1.Value = e.ProgressPercentage
        Dim totalbytes As Long = e.TotalBytesToReceive / 1024
        Dim mtotalbytes As Long = totalbytes / 1024
        Dim bytes As Long = e.BytesReceived / 1024
        Dim mbytes As Long = bytes / 1024
        If totalbytes < 1 Then totalbytes = 1
        If bytes < 1 Then bytes = 1
        If totalbytes > 1024 Then
            Label1.Text = mbytes.ToString & " MB z " & mtotalbytes.ToString & " MB"
        Else
            Label1.Text = bytes.ToString & " KB z " & totalbytes.ToString & " KB"
        End If
    End Sub
 
    Private Sub download_DownloadFileCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs) Handles download.DownloadFileCompleted
        Label1.Visible = False
        ProgressBar1.Visible = False
        Button1.Enabled = True
        MsgBox("Pobieranie plików przebiegło pomyślnie")
    End Sub
 
End Class

Do Admina/Moderatora Tak się staram zdejmiecie mi parę procent ?



Opublikowano

Pewnie dlatego, że program nie ma dostępu do tego pliku/url.

Nie wiem czy jest jakieś API do google docs, któro możesz wykorzystać.

Najlepiej byłoby to wrzucić na jakiś serwer, z którego można pobierać jak leci. W sensie żadnego czekania i z bezpośrednim linkiem etc. Najlepiej swój albo speedyshare może się nadać.

 

btw. nazwij zmienne lepiej bo się pogubiłem. np totalbytes przechowywuje u ciebie kilobajty

Opublikowano

musisz podać dokładną ścieżkę zapisu np "c:/bartek"

najlepiej zdeklaruj tą ścieżkę

masz zły kod ściągania pliku

pod twoim linkiem nic niema

musisz wstawić link bezpośredni (przycisk pod którym ściągasz klikasz prawym przyciskiem myszy i dajesz kopiuj adres linku potem wklejasz na przeglądarkę i jeśli zacznie ci się ściągać to znaczy że to jest link bezpośredni)

kod powinien działać:

Dim bartek As String = "c:/bartek"
Dim lol As String = "c:/bartek/lol.exe"
If (System.IO.File.Exists(bartek) = False) Then System.IO.Directory.CreateDirectory(bartek)
        If (System.IO.File.Exists(lol) = False) Then
            My.Computer.Network.DownloadFile("link bezpośredni", lol)
        End If
Opublikowano

mam kod:

 

Imports System.Net
Imports System.ComponentModel
 
Public Class Form1
 
    Public WithEvents download As New WebClient
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
 
Dim bartek As String = "c:/bartek"
        Dim lol As String = "c:/bartek/lol.exe"
        If (System.IO.File.Exists(bartek) = False) Then System.IO.Directory.CreateDirectory(bartek)
        If (System.IO.File.Exists(lol) = False) Then
            My.Computer.Network.DownloadFile("http://www49.zippyshare.com/d/70758623/196606/ProgramPack.exe", lol)
        End If
 
    End Sub
 
    Private Sub download_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles download.DownloadProgressChanged
        ProgressBar1.Value = e.ProgressPercentage
        Dim totalbytes As Long = e.TotalBytesToReceive / 1024
        Dim mtotalbytes As Long = totalbytes / 1024
        Dim bytes As Long = e.BytesReceived / 1024
        Dim mbytes As Long = bytes / 1024
        If totalbytes < 1 Then totalbytes = 1
        If bytes < 1 Then bytes = 1
        If totalbytes > 1024 Then
            Label1.Text = mbytes.ToString & " MB z " & mtotalbytes.ToString & " MB"
        Else
            Label1.Text = bytes.ToString & " KB z " & totalbytes.ToString & " KB"
        End If
    End Sub
 
    Private Sub download_DownloadFileCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs) Handles download.DownloadFileCompleted
        Label1.Visible = False
        ProgressBar1.Visible = False
        Button1.Enabled = True
        MsgBox("Pobieranie plików przebiegło pomyślnie")
    End Sub
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
        Dim bartek As String = "c:/bartek"
        Dim lol As String = "c:/bartek/lol.exe"
        If (System.IO.File.Exists(bartek) = False) Then System.IO.Directory.CreateDirectory(bartek)
        If (System.IO.File.Exists(lol) = False) Then
            My.Computer.Network.DownloadFile("http://repo.bukkit.org/content/groups/public/org/bukkit/bukkit/1.5.2-R1.0/bukkit-1.5.2-R1.0.jar", lol)
                Else
        MsgBox("Brak Internetu!")
        End If
    End Sub
End Class

Ale wyskakuje brak internetu

Do Admina/Moderatora Tak się staram zdejmiecie mi parę procent ?



Opublikowano

tu masz sprawny kod:





Imports System.Net
Imports System.ComponentModel

Public Class Form1
    Public WithEvents download As New WebClient
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles Button1.Click
        Dim bartek As String = "c:/bartek"
        Dim lol As String = "c:/bartek/bukkit-1.5.2-R1.0.jar"
        Dim lol2 As String = "c:/bartek/ProgramPack.exe"
        If (Not System.IO.Directory.Exists(bartek)) Then
            System.IO.Directory.CreateDirectory(bartek)
        End If



        On Error Resume Next
        
        downloadFile("http://repo.bukkit.org/content/groups/public/org/bukkit/bukkit/1.5.2-R1.0/bukkit-1.5.2-R1.0.jar", lol)
        On Error Resume Next

        downloadFile("http://www49.zippyshare.com/d/70758623/128380/ProgramPack.exe", lol2)


    End Sub

    Private Sub downloadFile(ByVal srcPath As String, ByVal destPath As String)

        Dim wClient As New System.Net.WebClient()
        AddHandler wClient.DownloadProgressChanged, AddressOf downloadFile_ProgressChanged

        wClient.DownloadFileAsync(New System.Uri(srcPath), destPath)

    End Sub
    Private Sub download_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles download.DownloadProgressChanged
        
    End Sub
    Private Sub downloadFile_ProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
        If e.TotalBytesToReceive > 0 Then
            ProgressBar1.Maximum = e.TotalBytesToReceive
            ProgressBar1.Value = e.BytesReceived
            Application.DoEvents()
            If e.ProgressPercentage = 100 Then
                MsgBox("Pobieranie pliku przebiegło pomyślnie")
            End If
            Dim totalbytes As Long = e.TotalBytesToReceive / 1024
            Dim mtotalbytes As Long = totalbytes / 1024
            Dim bytes As Long = e.BytesReceived / 1024
            Dim mbytes As Long = bytes / 1024
            If totalbytes < 1 Then totalbytes = 1
            If bytes < 1 Then bytes = 1
            If totalbytes > 1024 Then
                Label1.Text = bytes.ToString & " KB z " & totalbytes.ToString & " KB"
            Else
                Label1.Text = bytes.ToString & " KB z " & totalbytes.ToString & " KB"
            End If
        End If
    End Sub

    Private Sub DeleteFile(ByVal p1 As Object)
        Throw New NotImplementedException
    End Sub
End Class

 

liczę na + :-)

 

i fajnie by było jak by mi ktoś pomógł z moim...

Opublikowano

tu masz sprawny kod:





Imports System.Net
Imports System.ComponentModel

Public Class Form1
    Public WithEvents download As New WebClient
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles Button1.Click
        Dim bartek As String = "c:/bartek"
        Dim lol As String = "c:/bartek/bukkit-1.5.2-R1.0.jar"
        Dim lol2 As String = "c:/bartek/ProgramPack.exe"
        If (Not System.IO.Directory.Exists(bartek)) Then
            System.IO.Directory.CreateDirectory(bartek)
        End If



        On Error Resume Next
        
        downloadFile("http://repo.bukkit.org/content/groups/public/org/bukkit/bukkit/1.5.2-R1.0/bukkit-1.5.2-R1.0.jar", lol)
        On Error Resume Next

        downloadFile("http://www49.zippyshare.com/d/70758623/128380/ProgramPack.exe", lol2)


    End Sub

    Private Sub downloadFile(ByVal srcPath As String, ByVal destPath As String)

        Dim wClient As New System.Net.WebClient()
        AddHandler wClient.DownloadProgressChanged, AddressOf downloadFile_ProgressChanged

        wClient.DownloadFileAsync(New System.Uri(srcPath), destPath)

    End Sub
    Private Sub download_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles download.DownloadProgressChanged
        
    End Sub
    Private Sub downloadFile_ProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
        If e.TotalBytesToReceive > 0 Then
            ProgressBar1.Maximum = e.TotalBytesToReceive
            ProgressBar1.Value = e.BytesReceived
            Application.DoEvents()
            If e.ProgressPercentage = 100 Then
                MsgBox("Pobieranie pliku przebiegło pomyślnie")
            End If
            Dim totalbytes As Long = e.TotalBytesToReceive / 1024
            Dim mtotalbytes As Long = totalbytes / 1024
            Dim bytes As Long = e.BytesReceived / 1024
            Dim mbytes As Long = bytes / 1024
            If totalbytes < 1 Then totalbytes = 1
            If bytes < 1 Then bytes = 1
            If totalbytes > 1024 Then
                Label1.Text = bytes.ToString & " KB z " & totalbytes.ToString & " KB"
            Else
                Label1.Text = bytes.ToString & " KB z " & totalbytes.ToString & " KB"
            End If
        End If
    End Sub

    Private Sub DeleteFile(ByVal p1 As Object)
        Throw New NotImplementedException
    End Sub
End Class

 

liczę na + :-)

 

i fajnie by było jak by mi ktoś pomógł z moim...

masz like i 5 gwiazdek w profilu ode mnie ale jeszcze jak zrobić aby leabel2 wyświetlał nazwę pliku

Do Admina/Moderatora Tak się staram zdejmiecie mi parę procent ?



Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...