Results 1 to 29 of 29

Thread: Form_Activate question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Location
    Anywhere but here
    Posts
    161

    Form_Activate question

    This runs fine in the IDE but when I compile it and run it... I dont get the case select question... the program just exits after the Call is finished... Anyone have any ideas?

    VB Code:
    1. Private Sub Form_Activate()
    2.     Dim SaveName As String
    3.    
    4.     SaveName = "c:\auto.bat"
    5.     Set FSOFolder = MyFSO.GetFolder("d:\")
    6.     Call RecurseDirs(FSOFolder)
    7.     lblFile.Caption = "Scan Complete"
    8.      
    9.     Select Case MsgBox("Scan is now complete Notify Network Administrator?" vbYesNo
    10.     Case vbYes
    11.         Open SaveName For Output As #1
    12.             Print #1, "Yes... Notify Admin"
    13.         Close #1
    14.             Call MsgBox("Thank you for your time.", vbInformation + vbDefaultButton1, "")
    15.             End
    16.  
    17.     Case vbNo
    18.         Open SaveName For Output As #1
    19.             Print #1, "No... Don't Notify Admin"
    20.         Close #1
    21.             Call MsgBox("Thank you for your time.", vbInformation + vbDefaultButton1, "")
    22.            End
    23.     End Select
    24.    
    25. End Sub


    Thanks
    -------------------------
    My name says it all!

  2. #2
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    VB Code:
    1. If MsgBox("...", vbYesNo) = vbYes Then
    2.     '......
    3. Else
    4.     '......
    5. End If
    Roy

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Location
    Anywhere but here
    Posts
    161
    Originally posted by IROY55
    VB Code:
    1. If MsgBox("...", vbYesNo) = vbYes Then
    2.     '......
    3. Else
    4.     '......
    5. End If
    Im not at work so I cant test this... Im just curious, my code works in the IDE just not in the compiled exe. How does your code differ? ( I will test it in the morning) I guess what IM asking is how does it differ in logic. They both look like to me that they will acomplish the same thing? or am I wrong?

    Thanks again
    -------------------------
    My name says it all!

  4. #4
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    What's RecurseDirs? What does it do? Can you post code?
    Although, you are using End statement. It's like hitting a brick wall going 100 miles per hour. It's the worst you can do to your program. Try using Unload Me instead and if you need to unload more then 1 form then within Form_QueryUnload event loop through Forms collection and unload them one by one.
    Roy

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    I don't know why you are having that problem, but I hope you don't mind if I make a couple of comments about your code.

    1) Instead of doing Open SaveName For Output As #1, you should do

    Dim intFileNum As FreeFile
    Open SaveName For Output As intFileNum

    While you may have only one file in this app, FreeFile makes sure that the same file number is not already in use in your app and it's good practice.

    2) Instead of doing End, you should first make sure that all your forms are unloaded first.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Location
    Anywhere but here
    Posts
    161
    Private Sub RecurseDirs(MyFolder As Folder) - All this sub does is use the fso to dump a list of all folders on the C drive into a listbox.

    Thanks for the tips on using end and freefile, To be honest this is a prank program and will be very short lived. So I dont want to put much more into it.

    Thanks
    -------------------------
    My name says it all!

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by MartinLiss
    I don't know why you are having that problem, but I hope you don't mind if I make a couple of comments about your code.

    1) Instead of doing Open SaveName For Output As #1, you should do

    Dim intFileNum As FreeFile
    Open SaveName For Output As intFileNum

    While you may have only one file in this app, FreeFile makes sure that the same file number is not already in use in your app and it's good practice.
    Martin.. just a comment on your code now

    Should it not be
    VB Code:
    1. Dim intFileNum as Integer
    2. intFileNum = FreeFile
    3. Open SaveName For Output As intFileNum

  8. #8
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    It was just a quick typo I guess. ;-)
    Roy

  9. #9

  10. #10
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    kleinma: Yes, you are right of course.

    Wokawidget: There have been many discussions about the use of End and the end result (pun intended) is that there are occasions when End is appropriate and that the best way to terminate an app is to unload all forms followed by End.

  11. #11
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Martin: Agreed, but it's not something that should be used lightly. If beginners, who don't know the consiquences of using the End statement, use it all the time, then when they start creating complex applications then it could cause some problems and they won't know why.
    I make every effort not to use it, and have so far succeeded...

    When you you use the End statement? I am curious, as I have never come across an app that would require it...

    Woka

    PS Don't suppose you know anything about Len and LenB when dealing with udt's and buffer strings do you?

  12. #12
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    yeah i have never used END because doing
    VB Code:
    1. dim frm as form
    2. for each frm in forms
    3.     unload frm
    4. next
    has always done the trick of fully unloading an application for me and ending its process

  13. #13
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    the best way to terminate an app is to unload all forms followed by End
    Martin, don't take it offencively but it's one of the biggest nonsense I've ever heard from the experienced programmer. Sorry.
    Roy

  14. #14
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Wokawidget, nobody would do exactly this in a real program, but it is an example of why using End after unloading all forms is a good idea. Create a form with two command buttons, cmdStart and cmdEnd, add the code below and make an exe. Run the exe and click cmdStart and then cmdEnd. The application appears to go away but it can still be seen running if you take a look at TaskManager. Terminate it, remove the comment from the 'End line and make and run a new app. This time it goes away.
    VB Code:
    1. Private Sub cmdEnd_Click()
    2.  
    3.     Unload Me
    4.     'End
    5.    
    6. End Sub
    7.  
    8. Private Sub cmdStart_Click()
    9.     Dim x
    10.    
    11.     Do
    12.         DoEvents
    13.         x = x
    14.     Loop
    15.  
    16. End Sub

  15. #15

  16. #16
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    I may if your program's creating some processes (at the moment can't recalled any particular) wich cannot be terminated by End statement.
    Roy

  17. #17
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    The point is however, that I assume you would just unload all forms. All I am adding is a safety valve at the end that is there just in the extremely rare case something is still running. BTW did you try my example?

  18. #18
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Wouldn't it be safer to code in a "safety net"? Instead of End? Like your example BTW, never thought of using End in a situation like that. I would have forced my loop to end first...
    but it's one of the biggest nonsense I've ever heard from the experienced programmer.
    hehehehe

    Woka

    Off to play footy, it's the weekend...at last!!! BEER!

    C peoples next week...

  19. #19
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    I don't really have to try it as I know it'll work. The question, however, is not "Does it work or not?" but rather "What it does behind the scene?". And if do some researches - you'll find answer to be very ugly one. As I mentioned many times: it's like smashing a brick wall going 100+ miles per hour.
    Roy

  20. #20
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Martin, I will agree that your example provides a use for the END statement... but it would seem that your example and any others i can think of only serve as a work around for sloppy coding..

    if someone were to have loops running when the user has the ability to exit the application.. there should be code to drop out of the loop and clean up object etc on program termination

    because if something simlar to your example was applied to a real life programming situation. i would think it would be considered poor coding practice to have a loop running indefinitly with no ability to end it... (and i know what you gave was just an example) but any loop that would run similar to that should have a boolean switch in it or something to check

  21. #21
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    I agree with you that if all you do is End that that is "like smashing a brick wall going 100+ miles per hour", however if you unload all forms first I don't think you can do any harm. In any case I'm out of this thread.

  22. #22
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Whatever, Martin, I don't think you're listening. You have you opinion and it's unlikely for someone to change it. Tooooooo bad for you.
    Roy

  23. #23
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    IROY55 you must also take into account that you have an opinion that you are not going to change either...

    All the MSDN says about END is that it terminates the process without envoking the UNLOAD events of forms... so if you put it after unloading all forms then it really should be ok... but like i said in my post.. i don't see a REAL use for it.. but I don't think it is as bad as you say it is to use it in Martins context..

  24. #24
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    you must also take into account that you have an opinion that you are not going to change either...
    Oh, sure I do. But the difference is - I alwys listen and always try to understand what makes me wrong.
    Roy

  25. #25
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    but where does it say that he is wrong?

    While I am on the side of "DON'T USE END" I have yet to read that after unloading all forms (and closing/setting to nothing all objects) that the END statement will do damage to anything... if it was that HORRIBLE why is it in the language??? it is just advised against by Microsoft to use before taking care of any shutdown code that should be envoked in your app

  26. #26
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    if it was that HORRIBLE why is it in the language???
    They carried it over from very first Basic as Bill didn't have any better solution at the time (I guess). But times have changed and we moved from MS DOS to WinXP with the speed of sonic and difference between the two is huge (unpropotional if you will) so use of that statement may hurt not your program but OS itself so it will simply crush one day.
    Roy

  27. #27
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    And besides there are lots of things in the language that are horrible: While - Wend is one of them...
    Roy

  28. #28
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by IROY55
    They carried it over from very first Basic as Bill didn't have any better solution at the time (I guess). But times have changed and we moved from MS DOS to WinXP with the speed of sonic and difference between the two is huge (unpropotional if you will) so use of that statement may hurt not your program but OS itself so it will simply crush one day.
    well like i said i am not going to argue the point.. but i have seen code with END in it after unloading all forms and objects and it has not done anything to damage the OS.. but i have not seen a case where it has damaged the OS...

    I am sure it is a good debate topic... but as i said before i don't use END anyways..

  29. #29

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Location
    Anywhere but here
    Posts
    161
    Eeeekk!! didn't mean to start all this Anyway.. thanks for all the input
    -------------------------
    My name says it all!

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