VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,450 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,590 people online right now. Registration is fast and FREE... Join Now!




EventHandler setting value of -1

 

EventHandler setting value of -1, DotNetZip library

RPGonzo

1 Jul, 2009 - 09:41 AM
Post #1

// Note to self: hmphh .... I forgot
Group Icon

Joined: 16 Mar, 2009
Posts: 743



Thanked: 89 times
Dream Kudos: 25
My Contributions
CODE

Me.SetProgressBars()
                        AddHandler zip.SaveProgress, New EventHandler(Of SaveProgressEventArgs)(AddressOf Me.zip_SaveProgress)
                        zip.Save(target)


Took some snippets from a MSDN page and molded it into my project ... problem is on every run its setting a value of -1 to something and i cant for the life of me figure out what to!

CODE

Private Sub zip_SaveProgress(ByVal sender As Object, ByVal e As SaveProgressEventArgs)
        Select Case e.EventType
            Case ZipProgressEventType.Saving_AfterWriteEntry
                Me.StepArchiveProgress(e)
                Exit Select
            Case ZipProgressEventType.Saving_Completed
                Me.SaveCompleted()
                Exit Select
            Case ZipProgressEventType.Saving_EntryBytesRead
                Me.StepEntryProgress(e)
                Exit Select
        End Select
        If Me._saveCanceled Then
            e.Cancel = True
        End If
    End Sub


thats the sub its calling as well ... i can post wahtever more code it is main thing im looking for is a better debugging method to narrow down what is being set to -1 or if someone can see it off hand :-/

and the 3 subs it calls it that sub ...

CODE

Private Sub StepArchiveProgress(ByVal e As SaveProgressEventArgs)
        If Me.progressBar1.InvokeRequired Then
            Me.progressBar1.Invoke(New SaveEntryProgress(AddressOf Me.StepArchiveProgress), New Object() {e})
        ElseIf Not Me._saveCanceled Then
            Me._nFilesCompleted += 1
            Me.progressBar1.PerformStep()
            Me._totalBytesAfterCompress = (Me._totalBytesAfterCompress + e.CurrentEntry.CompressedSize)
            Me._totalBytesBeforeCompress = (Me._totalBytesBeforeCompress + e.CurrentEntry.UncompressedSize)
            ' progressBar2 is the one dealing with the item being added to the archive
            ' if we got this event, then the add of that item (or file) is complete, so we
            ' update the progressBar2 appropriately.
            Me.progressBar2.Value = Me.progressBar2.Maximum = 1
            MyBase.Update()
        End If
    End Sub


    Private Sub SaveCompleted()
        If Me.lblStatus.InvokeRequired Then
            Me.lblStatus.Invoke(New MethodInvoker(AddressOf SaveCompleted))
            'Me.lblStatus.Invoke(New MethodInvoker(Me, DirectCast(Me.SaveCompleted, IntPtr)))
        Else
            Me.lblStatus.Text = String.Format("Done, Compressed {0} files, {1:N0}% of original", Me._nFilesCompleted, ((100 * Me._totalBytesAfterCompress) / CDbl(Me._totalBytesBeforeCompress)))
            Me.ResetState()
        End If
    End Sub


    Private Sub StepEntryProgress(ByVal e As SaveProgressEventArgs)
        If Me.progressBar2.InvokeRequired Then
            Me.progressBar2.Invoke(New SaveEntryProgress(AddressOf Me.StepEntryProgress), New Object() {e})
        ElseIf Not Me._saveCanceled Then
            If (Me.progressBar2.Maximum = 1) Then
                Dim entryMax As Long = e.TotalBytesToTransfer
                Dim absoluteMax As Long = &H7FFFFFFF
                Me._progress2MaxFactor = 0
                Do While (entryMax > absoluteMax)
                    entryMax = (entryMax / 2)
                    Me._progress2MaxFactor += 1
                Loop
                If (CInt(entryMax) < 0) Then
                    entryMax = (entryMax * -1)
                End If
                Me.progressBar2.Maximum = CInt(entryMax)
                Me.lblStatus.Text = String.Format("{0} of {1} files...({2})", (Me._nFilesCompleted + 1), Me._entriesToZip, e.CurrentEntry.FileName)
            End If
            Dim xferred As Integer = CInt((e.BytesTransferred >> Me._progress2MaxFactor))
            Me.progressBar2.Value = IIf((xferred >= Me.progressBar2.Maximum), Me.progressBar2.Maximum, xferred)
            MyBase.Update()
        End If
    End Sub


This post has been edited by RPGonzo: 1 Jul, 2009 - 09:43 AM

User is offlineProfile CardPM
+Quote Post


LoveIsNull

RE: EventHandler Setting Value Of -1

1 Jul, 2009 - 07:14 PM
Post #2

Disbanding my Ignorance
****

Joined: 10 Mar, 2009
Posts: 536



Thanked: 45 times
My Contributions
Is there an exception actually being thrown? If so, what does it say?

You can try exception handling by putting the offending code into a Try...Catch block
CODE
Try

Catch ex As Exception
       Debug.WriteLine(ex.ToString)
End Try


Or set breakpoints at locations within the code to narrow down where things are starting to go wrong.
User is offlineProfile CardPM
+Quote Post

RPGonzo

RE: EventHandler Setting Value Of -1

2 Jul, 2009 - 07:23 AM
Post #3

// Note to self: hmphh .... I forgot
Group Icon

Joined: 16 Mar, 2009
Posts: 743



Thanked: 89 times
Dream Kudos: 25
My Contributions
It was actually a first chance exception ... after turning on break on all common language errors it was a typo sleep.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 01:51AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month