Results 1 to 4 of 4

Thread: problem canceling process

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Hi,

    I asked a similar question recently and implemented the various suggestions that I received but, I ran into an unexpected problem which I did not explain in the first post..

    Here's the situation:

    I have a form which has 2 buttons. cmdStart and cmdCancel. As you can probably already guess, the cmdStart starts the process and cmdCancel cancels the process.

    I used the following code behind the cmdCancel button:

    Code:
        xVar = MsgBox("Are you sure you wish to cancel downloading?", _
            vbQuestion + vbYesNo)
        
        If xVar = 6 Then
            '-- cancel download operation
            If Winsock1.State <> sckClosed Then
                Winsock1.Close 'close socket if open
            End If
            Unload Me
        End If
    However, the code behing cmdStart is "modular" in nature. For example:

    cmdStart calls a sub which does some various processing, calls another function to get a value, takes that value and does a calculation, etc...

    I beleive that the above CANCEL code would in fact work if the code behind cmdSend was not modular in nature. But, the fact is that I am using modular programming so the above cancel code raises various errors througout the various functions/subs depending on where the fucntion/sub was when the user hit the Cancel button. I do not want to put an error handling routine in each function/sub that cmdStart calls to handle the cancelling.. I'm sure there is a better way to handle "Cancelling" in modular programming..

    Does anyone have any ideas on how to easily and "effeciently" cancel processing when you're dealing with modular programming?

    Thanks,

    Dan

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    The best way is exceptions, which will appear in the next version of VB (they've been in other languages for ages). Other than that, how about setting some global variable, then exiting up the call stack? (the call stack is the functions that have been called in reverse order, ie the current function is on top, it's caller is next, and so on)
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    That sounds interesting.. I'd like to try it but don't know how.. How do you "exit up the call stack"? An example would be appreciated..

    Dan

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Something like this:
    Code:
    Dim iErrorCode As Integer
    Sub RootSub()
        iErrorCode = 0 ' No error
        NextSub
        If iErrorCode <> 0 Then
            Debug.Print "Error " & iErrorCode & " encountered"
            Exit Sub
        End If
    
        ' Continue
    End Sub
    Sub NextSub()
        OtherSub
        If iErrorCode <> 0 Then
            Exit Sub
        End If
        DifferentSub
    End Sub
    Sub OtherSub
        iErrorCode = 1
    End Sub
    Sub DifferentSub
        Debug.Print "Hit DifferentSub"
    End Sub
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width