|
-
Oct 10th, 2002, 03:55 PM
#1
Thread Starter
Addicted Member
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:
Private Sub Form_Activate()
Dim SaveName As String
SaveName = "c:\auto.bat"
Set FSOFolder = MyFSO.GetFolder("d:\")
Call RecurseDirs(FSOFolder)
lblFile.Caption = "Scan Complete"
Select Case MsgBox("Scan is now complete Notify Network Administrator?" vbYesNo
Case vbYes
Open SaveName For Output As #1
Print #1, "Yes... Notify Admin"
Close #1
Call MsgBox("Thank you for your time.", vbInformation + vbDefaultButton1, "")
End
Case vbNo
Open SaveName For Output As #1
Print #1, "No... Don't Notify Admin"
Close #1
Call MsgBox("Thank you for your time.", vbInformation + vbDefaultButton1, "")
End
End Select
End Sub
Thanks
-------------------------
My name says it all!
-
Oct 10th, 2002, 03:58 PM
#2
PowerPoster
VB Code:
If MsgBox("...", vbYesNo) = vbYes Then
'......
Else
'......
End If
-
Oct 10th, 2002, 08:06 PM
#3
Thread Starter
Addicted Member
Originally posted by IROY55
VB Code:
If MsgBox("...", vbYesNo) = vbYes Then
'......
Else
'......
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!
-
Oct 10th, 2002, 09:06 PM
#4
PowerPoster
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.
-
Oct 10th, 2002, 09:41 PM
#5
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.
-
Oct 11th, 2002, 07:19 AM
#6
Thread Starter
Addicted Member
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!
-
Oct 11th, 2002, 07:35 AM
#7
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:
Dim intFileNum as Integer
intFileNum = FreeFile
Open SaveName For Output As intFileNum
-
Oct 11th, 2002, 07:42 AM
#8
PowerPoster
It was just a quick typo I guess. ;-)
-
Oct 11th, 2002, 07:55 AM
#9
End *shakes head*
What you should use is:
Woka
-
Oct 11th, 2002, 09:38 AM
#10
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.
-
Oct 11th, 2002, 09:45 AM
#11
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?
-
Oct 11th, 2002, 09:54 AM
#12
yeah i have never used END because doing
VB Code:
dim frm as form
for each frm in forms
unload frm
next
has always done the trick of fully unloading an application for me and ending its process
-
Oct 11th, 2002, 10:32 AM
#13
PowerPoster
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.
-
Oct 11th, 2002, 10:35 AM
#14
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:
Private Sub cmdEnd_Click()
Unload Me
'End
End Sub
Private Sub cmdStart_Click()
Dim x
Do
DoEvents
x = x
Loop
End Sub
-
Oct 11th, 2002, 10:49 AM
#15
IROY55: No offense taken. I used to be in the "never use End" camp, but examples like the one I gave convinced me that unloading all forms followed by End is the way to go. It can't hurt, right?
-
Oct 11th, 2002, 10:53 AM
#16
PowerPoster
I may if your program's creating some processes (at the moment can't recalled any particular) wich cannot be terminated by End statement.
-
Oct 11th, 2002, 10:57 AM
#17
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?
-
Oct 11th, 2002, 11:00 AM
#18
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...
-
Oct 11th, 2002, 11:01 AM
#19
PowerPoster
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.
-
Oct 11th, 2002, 11:04 AM
#20
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
-
Oct 11th, 2002, 11:09 AM
#21
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.
-
Oct 11th, 2002, 11:11 AM
#22
PowerPoster
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.
-
Oct 11th, 2002, 11:27 AM
#23
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..
-
Oct 11th, 2002, 11:33 AM
#24
PowerPoster
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.
-
Oct 11th, 2002, 11:38 AM
#25
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
-
Oct 11th, 2002, 11:45 AM
#26
PowerPoster
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.
-
Oct 11th, 2002, 11:47 AM
#27
PowerPoster
And besides there are lots of things in the language that are horrible: While - Wend is one of them...
-
Oct 11th, 2002, 12:58 PM
#28
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..
-
Oct 11th, 2002, 01:22 PM
#29
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|