Results 1 to 22 of 22

Thread: exiting subs

  1. #1

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    On form1 i'am uploading and as a status i have a form2 pop up...on form2 i have a cancel button...how would i get it so when the cancel button is clicked..the upload is terminated and the Command_Click() sub on form one is exited.
    This is what i tried:
    Code:
    'under the cancel button
    Form1.Enabled = True
    Form1.iNet1.Cancel
    Unload Form2
    so how would i stop the sub from continuing (something like "Exit Form1.Command1_Click() Sub" and stop the upload process.

    Thank you,
    D!m
    Dim

  2. #2
    Guest
    Use Exit Sub when you want to exit. Here is a visual example for better understanding

    Code:
    Private Sub Form_Load()
    
       'All code here will be executed
       
       Exit Sub
    
       'All code on this end will not be executed because we
       'have chosen to exit the sub.
    
    End Sub

  3. #3

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    =/ i think you better read the question
    I want to exit a sub that is on another form.
    Dim

  4. #4
    Addicted Member
    Join Date
    Jul 1999
    Location
    St-Élie d'Orford, Quebec, Canada
    Posts
    133
    Hi,

    I don't get it, how could it not exit ?
    Are you in a loop or something...<





  5. #5

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    I want to exit a sub that is being carried out on another form!
    I have two forms, on form1 an upload button is pressed and starts uploading...while form2 shows up as a status window and on form2 there is cancel button that...when pressed...has to cancel the upload and exit a sub on form1.
    Clear?

    Thanx,
    D!m

    Dim

  6. #6
    Addicted Member
    Join Date
    Jul 1999
    Location
    St-Élie d'Orford, Quebec, Canada
    Posts
    133
    I've done this more than once and I never had any trouble
    exiting subs or forms.

    are you sure your doing this the right way ?

  7. #7

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    omg! i know that "EXIT SUB" will exit the sub that contains that code....BUT i need to exit a sub that is on another form!
    Where is Matt when he's needed.
    I mean don't you understand what i'm trying to do?
    EXIT a SUB on a DIFF FORM!
    Sorry for being so rough but i don't know of any other way of explaining it to you guys.

    Thanx,
    D!m
    Dim

  8. #8
    Guest
    An alternative solution: Place your code into a Timer and disable the Timer when it is finished. This way will make it act as a normal Sub and it will allow you to enable and disable (exit) it.

    Put this code in Form2

    Code:
    Private Sub Timer1_Timer()
    
        'Do code here other code here
        
        Timer1.Enabled = False
    
    End Sub
    Now when you cant to Exit that code, just disable the Timer.

    Code:
    Private Sub Command1_Click()
    
        Form2.Timer1.Enabled = False
    
    End Sub

  9. #9
    Addicted Member
    Join Date
    Jul 1999
    Location
    St-Élie d'Orford, Quebec, Canada
    Posts
    133
    Hi,

    your code should look something like this, I've never used
    the internet or upload control but I think it should be
    done like this...

    ' On form1 upload button
    Private sub Upload_Click

    iNet.StartUpload ' Don't know if it exists

    form2.show

    while iNet.EndUpload <> true and Form2.bCancelFlag <> true

    ' Do what you want with the progress bar...

    DOEVENTS
    wend

    End sub

    if the function doesn't want to exit it may be because
    your stuck in a loop or you've loaded your form modaly
    and don't know when to close it ( when the upload is over).


    AND BY THE WAY : we all know you don't want to exit the
    sub on the second form so has you said, don't be so rude !

  10. #10

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Sorry Vince it's just that it's a bit frusterating when i fail to communicate properly with ppl that are trying to help.
    Thanx for the tips...i think i can take it from here.

    Thanx,
    D!m
    Dim

  11. #11
    Addicted Member
    Join Date
    Jul 1999
    Location
    St-Élie d'Orford, Quebec, Canada
    Posts
    133
    And also,


    if you want your form2 to be modal (probably) you will
    have to poll your internet control in the second form
    in order to decide wend the transfer is completed or
    canceled. There you unload your form2 and it will
    continue in form1 upload_Click and eventualy exit...

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Hope youre knowing what youre talking about, YOU CAN'T EXIT ANY SUB ON ANOTHER FORM.

    You can only exit a sub from within the sub you call exit sub within, or ending the sub. So if you want to simulate exit sub you have to enable other events to get fired while your sub is running by using doevents statement, and then exit your sub under a condition you set in your event.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  13. #13
    Guest
    You do not need to use DoEvents. As I stated earlier, if he placed his code in a Timer and disabled the Timer at the end of the code, it will act as a normal sub.

    Now, this is an advantage because we can enable or disable the "sub" by changing the enabled property of the Timer.

  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I wouldn't prefer that solution, but if Dim find's it useful enough, it's ok. You don't want to ask me the disadvantages with using a timer?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  15. #15

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    i still haven't solved this problem...the code works fine in Win98 and NT but not 95. For some reason it just skips through the upload section and says that the upload is done.
    =/
    Dim

  16. #16
    Guest
    Kedaman, the Timer will not be used for the purpose of a Timer. It will be used for flexibility purposes so we can enable and disable the Sub from a different Form. It's bascially the same as a normal Sub.

  17. #17
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    ACtually that isn't a solution then, if you use the timer event as the procedure, it won't exit if you set the enabled to false, it will just run through the whole sub.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  18. #18
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    What code Dim?

    I've just picked up the thread and apart from the interesting philisophical debate that seems to be brewing (I like those sort since there is never a right answer ) I was curious as to what code you used. There were two possible solutions posted and either one or both of these don't work under win95 for you.

    If you are still seeking help, perhaps you could advise which code you used?

    Cheers
    Paul Lewis

  19. #19

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Code:
    'connects
    With Inet1
        .Cancel
        .Protocol = icFTP
        .url = Text1.Text
        .UserName = Text2.Text
        .Password = Text3.Text
    End With
    and i have this sequence repeating fove times for the 5 different text boxes containing file name/paths.
    If Text4.Text <> "" Then
            Dim filename As String
            filename = random & "--" & Text14.Text
            Inet1.Execute , "PUT " & Text4.Text & " " & "./public_ftp/" & filename
        While Inet1.StillExecuting
                DoEvents
        Wend
        Else
            Resume Next
        End If
    and that's it...5 files being uploaded in the same sub...works just fine in 98 and NT but 95 just shoots through the sub and saying that the upload is complete.
    Don't bother with the random and -- stuff it's just something that needs to be there.

    Any ideas?
    D!m

    PS. And i can't use the cancel method...it just won't cancell. I posted a diff thread for that problem. =/ i'm just full of problems aren't i?

    [Edited by Dim on 07-19-2000 at 12:25 AM]
    Dim

  20. #20
    New Member
    Join Date
    Jun 2000
    Location
    Okla
    Posts
    9
    I have a similar program that loops through a text file of file names (urls) to download (the url, and local path are displayed in text boxes).
    To pause, I use ...

    Private Sub cmdPause_Click()
    pause = 1
    Label2.Caption = "Downloading will stop after the current" & vbCrLf & _
    "Image download. Hold your sausage."
    Label2.Visible = True
    End Sub

    The begining of my loop checks for files that are already d/l'd. Before I Loop to get the next file name I have

    If pause = 1 Then
    Exit Do
    Close #dl 'file of urls
    cmdStart.Caption = "Resume"
    cmdPause.Visible = False
    End If
    Loop

    I'm waiting for the current d/l to stop, other wise the file would be garbage, or a zero byte file.

  21. #21

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    But your program requires the user to press the pause and so...i'lltry to work around that...but i'm hoping that it isn't my coding that is causing the actions to act wierd in 95 and just MY box that is screwing this up, i will test it out tomorrow on another win95 box and hope that it works.
    Thanx for your input,
    D!m
    Dim

  22. #22
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Thumbs up

    Easy!

    Ok, Form one starts the action in some sort of loop, as data is arriving the loop is updating form2 which has a "Cancel" button.. yes?

    Okay, in a module put a Boolean Variable called Cancelled (for example) and when your loop starts set it to false.

    also have

    If Cancelled = True then
    ' do any file cleanups
    Exit Sub
    End If

    and for the cancel button have it set the boolean to True then unload the form2, command is passed back to the loop which then exit's on the next interation!


    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

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