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

VB.NET Discussion :

L'opération arithmétique a provoqué un dépassement de capacité. [Débutant]


Sujet :

VB.NET

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2018
    Messages : 12
    Points : 13
    Points
    13
    Par défaut L'opération arithmétique a provoqué un dépassement de capacité.
    Bonjour,
    j'ai télécharger un programme en Open SOurce pour l'intégrer a mon projet, mais le problème ce que ce programme de téléchargement s'arrete toujours a environ 21000 K/o.

    Je ne sais comment regler apparament c'est une histoire de 32 bits, je ne sais trop si une personne pourrais m'aider.

    Voici l'erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    L'exception System.OverflowException n'a pas été gérée par le code utilisateur
      HResult=-2146233066
      Message=L'opération arithmétique a provoqué un dépassement de capacité.
      Source=SimpleDownloadFile
      StackTrace:
           à SimpleDownloadFile.mainForm.BackgroundWorker1_DoWork(Object sender, DoWorkEventArgs e) dans D:\Users\Théo\Downloads\4\mainForm.vb:ligne 136
           à System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
           à System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
      InnerException:
    Merci

    Je précise que je lui est envoyer un message il y a une semaine mais bon son projet date de il y a 10 ans donc je pense que il la un peu laisser de coter

    Nom : Capture.PNG
Affichages : 2004
Taille : 105,0 Ko

    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
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    Imports System.Net
    Public Class mainForm
     
        Dim whereToSave As String 'Where the program save the file
     
        Delegate Sub ChangeTextsSafe(ByVal length As Long, ByVal position As Integer, ByVal percent As Integer, ByVal speed As Double)
        Delegate Sub DownloadCompleteSafe(ByVal cancelled As Boolean)
     
        Public Sub DownloadComplete(ByVal cancelled As Boolean)
            Me.txtFileName.Enabled = True
            Me.btnDownload.Enabled = True
            Me.btnCancel.Enabled = False
     
            If cancelled Then
     
                Me.Label4.Text = "Cancelled"
     
                MessageBox.Show("Download aborted", "Aborted", MessageBoxButtons.OK, MessageBoxIcon.Information)
     
     
            Else
                Me.Label4.Text = "Successfully downloaded"
     
                MessageBox.Show("Successfully downloaded!", "All OK", MessageBoxButtons.OK, MessageBoxIcon.Information)
     
     
            End If
     
            Me.ProgressBar1.Value = 0
            Me.Label5.Text = "Downloading: "
            Me.Label6.Text = "Save to: "
            Me.Label3.Text = "File size: "
            Me.Label2.Text = "Download speed: "
            Me.Label4.Text = ""
     
        End Sub
     
        Public Sub ChangeTexts(ByVal length As Long, ByVal position As Integer, ByVal percent As Integer, ByVal speed As Double)
     
            Me.Label3.Text = "File Size: " & Math.Round((length / 1024), 2) & " KB"
     
            Me.Label5.Text = "Downloading: " & Me.txtFileName.Text
     
            Me.Label4.Text = "Downloaded " & Math.Round((position / 1024), 2) & " KB of " & Math.Round((length / 1024), 2) & "KB (" & Me.ProgressBar1.Value & "%)"
     
            If speed = -1 Then
                Me.Label2.Text = "Speed: calculating..."
            Else
                Me.Label2.Text = "Speed: " & Math.Round((speed / 1024), 2) & " KB/s"
            End If
     
            Me.ProgressBar1.Value = percent
     
     
        End Sub
     
        Private Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownload.Click
     
            If Me.txtFileName.Text <> "" AndAlso Me.txtFileName.Text.StartsWith("http://") Then
     
     
                Me.SaveFileDialog1.FileName = Me.txtFileName.Text.Split("/"c)(Me.txtFileName.Text.Split("/"c).Length - 1)
     
                If Me.SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
     
                    Me.whereToSave = Me.SaveFileDialog1.FileName
     
                    Me.SaveFileDialog1.FileName = ""
     
                    Me.Label6.Text = "Save to: " & Me.whereToSave
     
                    Me.txtFileName.Enabled = False
                    Me.btnDownload.Enabled = False
                    Me.btnCancel.Enabled = True
     
                    Me.BackgroundWorker1.RunWorkerAsync() 'Start download
     
                End If
     
            Else
     
                MessageBox.Show("Please insert valid URL for download", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
     
            End If
     
        End Sub
     
        Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
     
            'Creating the request and getting the response
            Dim theResponse As HttpWebResponse
            Dim theRequest As HttpWebRequest
            Try 'Checks if the file exist
     
                theRequest = WebRequest.Create(Me.txtFileName.Text)
                theResponse = theRequest.GetResponse
            Catch ex As Exception
     
                MessageBox.Show("An error occurred while downloading file. Possibe causes:" & ControlChars.CrLf & _
                                "1) File doesn't exist" & ControlChars.CrLf & _
                                "2) Remote server error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
     
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete)
     
                Me.Invoke(cancelDelegate, True)
     
                Exit Sub
            End Try
            Dim length As Long = theResponse.ContentLength 'Size of the response (in bytes)
     
            Dim safedelegate As New ChangeTextsSafe(AddressOf ChangeTexts)
            Me.Invoke(safedelegate, length, 0, 0, 0) 'Invoke the TreadsafeDelegate
     
            Dim writeStream As New IO.FileStream(Me.whereToSave, IO.FileMode.Create)
     
            'Replacement for Stream.Position (webResponse stream doesn't support seek)
            Dim nRead As Integer
     
            'To calculate the download speed
            Dim speedtimer As New Stopwatch
            Dim currentspeed As Double = -1
            Dim readings As Integer = 0
     
            Do
     
                If BackgroundWorker1.CancellationPending Then 'If user abort download
                    Exit Do
                End If
     
                speedtimer.Start()
     
                Dim readBytes(4095) As Byte
                Dim bytesread As Integer = theResponse.GetResponseStream.Read(readBytes, 0, 8192)
     
                nRead += bytesread
                Dim percent As Short = (nRead * 100) / length
     
                Me.Invoke(safedelegate, length, nRead, percent, currentspeed)
     
                If bytesread = 0 Then Exit Do
     
                writeStream.Write(readBytes, 0, bytesread)
     
                speedtimer.Stop()
     
                readings += 1
                If readings >= 5 Then 'For increase precision, the speed it's calculated only every five cicles
                    currentspeed = 20480 / (speedtimer.ElapsedMilliseconds / 1000)
                    speedtimer.Reset()
                    readings = 0
                End If
            Loop
     
            'Close the streams
            theResponse.GetResponseStream.Close()
            writeStream.Close()
     
            If Me.BackgroundWorker1.CancellationPending Then
     
                IO.File.Delete(Me.whereToSave)
     
                Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete)
     
                Me.Invoke(cancelDelegate, True)
     
                Exit Sub
     
            End If
     
            Dim completeDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete)
     
            Me.Invoke(completeDelegate, False)
     
        End Sub
     
        Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Label4.Text = ""
        End Sub
     
        Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
            Me.BackgroundWorker1.CancelAsync() 'Send cancel request
        End Sub
     
        Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
            MessageBox.Show("Created by Carmine_XX (www.thetotalsite.it)" & ControlChars.CrLf & "To report bugs/suggestions/comments please contact me by email: pikachu31@gmail.com or in the project page on CodeProject.com", "About", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Sub
    End Class

  2. #2
    Inactif  

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2012
    Messages
    4 904
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2012
    Messages : 4 904
    Points : 10 168
    Points
    10 168
    Billets dans le blog
    36
    Par défaut
    Bonjour,

    Tu t'es fait prendre par la conversion implicite de VB. Dans une opération mathématique aucune valeur de peut dépasser la valeur maximale du type le plus "petit". Si mes souvenirs sont exacts, le maximum du type short c'est 255. Tu ne peux jamais dépasser 255 dans tes calculs.

    Mais, si c'est juste pour afficher un pourcentage arrondi, tu peux mettre ta variable en single, ou même en double, et utiliser les diverses possibilités de formatage, pour afficher la valeur. La valeur n'est pas affectée, mais c'est juste la façon dont elle est affichée.

    Oupss! Ce n'est pas 255, mais 32767. C'est le type byte qui arrête à 255. Mais le principe ne change pas. Si tu as variable de type byte, tu reste à 255.
    À ma connaissance, le seul personnage qui a été diagnostiqué comme étant allergique au mot effort. c'est Gaston Lagaffe.

    Ô Saint Excel, Grand Dieu de l'Inutile.

    Excel n'a jamais été, n'est pas et ne sera jamais un SGBD, c'est pour cela que Excel s'appelle Excel et ne s'appelle pas Access junior.

  3. #3
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2018
    Messages : 12
    Points : 13
    Points
    13
    Par défaut
    Je tiens d'abords a vous remercie pour votre réponse qui me remet de l'espoir.

    Cela étant dit je ne comprends pas tout a fait ce que je doit modifier. Si vous pourriez me montrer. Sinon je peut enlever les pourcentage mais ce qui toucherais la progressbar j'imagine ?

  4. #4
    Expert éminent sénior
    Avatar de ProgElecT
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2004
    Messages
    6 078
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Décembre 2004
    Messages : 6 078
    Points : 17 069
    Points
    17 069
    Par défaut
    Salut

    Essais de modifier le type du paramètre percent
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
        'Public Sub ChangeTexts(ByVal length As Long, ByVal position As Integer, ByVal percent As Integer, ByVal speed As Double)
        Public Sub ChangeTexts(ByVal length As Long, ByVal position As Integer, ByVal percent As single, ByVal speed As Double)
    pourquoi pas, pour remercier, un pour celui/ceux qui vous ont dépannés.
    saut de ligne
    OOOOOOOOO👉 → → Ma page perso sur DVP ← ← 👈

  5. #5
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2018
    Messages : 12
    Points : 13
    Points
    13
    Par défaut Résolu
    J'ai finalement opté pour une autre facon

    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
    Imports System.Net
     
    Public Class FrmDownload
        Dim wc As WebClient
     
        Private Sub FrmDownload_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            wc = New WebClient()
        End Sub
     
        Private Sub btnPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPaste.Click
            txtURL.Text = My.Computer.Clipboard.GetText() 'Il est utilisé pour obtenir l'URL copiée du presse-papiers
        End Sub
     
        Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
            Dim fldBrowse As New FolderBrowserDialog()
            If fldBrowse.ShowDialog() = DialogResult.OK Then
                txtPath.Text = fldBrowse.SelectedPath
            End If
        End Sub
     
        Private Sub btnDwn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDwn.Click
            'pour montrer la progression du téléchargement
            AddHandler wc.DownloadProgressChanged, AddressOf ProgChanged
            wc.DownloadFileAsync(New Uri(txtURL.Text), txtPath.Text + "\" + txtName.Text)
            'il est utilisé pour télécharger un fichier depuis l'URL spécifiée jusqu'à la destination
        End Sub
     
        Private Sub ProgChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
            pbStatus.Value = e.ProgressPercentage 'Obtenir la progression du téléchargement en cours
            lblProgPerc.Text = e.ProgressPercentage.ToString() + "%"
            lblln.Text = String.Format("{0} MB's / {1} MB's", (e.BytesReceived / 1024D / 1024D).ToString("0.00"), (e.TotalBytesToReceive / 1024D / 1024D).ToString("0.00"))
        End Sub
    End Class
    Merci beaucoup pour votre aide

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

Discussions similaires

  1. Réponses: 0
    Dernier message: 30/10/2014, 19h01
  2. corriger un programme
    Par karika dans le forum MATLAB
    Réponses: 2
    Dernier message: 26/05/2011, 10h09
  3. corriger un programme
    Par batjork dans le forum MATLAB
    Réponses: 5
    Dernier message: 07/01/2008, 10h21
  4. Réponses: 7
    Dernier message: 27/04/2006, 14h51

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