Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

End Vb Application

Status
Not open for further replies.

bsanthu

Programmer
Oct 31, 2002
14
IN
I have my VB application as Exe. I am launching my exe from another vb
application using create process api. I am using a End statement to stop my
vb application in form load if some error occurs in form load code. But it
is not closing the form. It is appearing in the screen. I want to completely
exit from my application if some error occurs in form load code with out
calling unload.

How to do?

Any help.........

-Thanks in advance
Santhakumar B

 
Santhu,

Let me tell u first, generally It is a bad idea to use 'End' at any point in your VB app.. I'll suggest u to do the error trapping in the form load, and set some sort of a boolean flag, and do the unload code in activate event after checking that flag. All the Best
Praveen Menon
pcmin@rediffmail.com
 
Agreed. Useing END is about as good as pulling the plug of your computer from the wall socket. Do your error trap then UNLOAD ME
 
this is just to complete PraveenMenon and SemperFiDownUnda idea

Public Sub UnloadAllForms()
Dim Form As Form
For Each Form In Forms
Unload Form
Set Form = Nothing
Next Form
End Sub
Please pardon the grammar.
Not good in english.
 
Whilst I agree about never using END - Im a bit puzzled by the original prob Im sure all forms will be closed by the END statement and the form that has the END in its load event will never be shown. Is the END being executed ?

Any comments ?

cjw
 
i dont if i'm right with this.

but i do know that this has to do with the memory that a form uses when loaded. if the form itself was not properly unloaded it will not free-up the memory it uses.

again i dont know if i'm really right with this. Please pardon the grammar.
Not good in english.
 

I would use a public method (typically "Main" is a proceedure used a public Module, which the application uses when starting up - set the start up proceedure in PROJECT|PROPERTIES)

Then, when the application starts by using that ("Main") proceedure in the public module, that is where you would use code to load the form.

I would use an error catcher in the form class and throw any errors back to the "Main" proceedure.

When the main sub receives the error, it turns back around and unloads the form and ends the program.

No problem using "End" after that. Using the "End" method is only bad if used wrong. Then again, if you have correctly unloaded everything, then, VB being the tidy housekeeper that it is, there shouldn't be really a need to use the "End" method.
I use it anyways, and always have, just as an extra. Never have any problems with it. But, I unload everything first and make sure I have no open objects left (which may happen when using the "NEW" key word in the declaration section of a module ar Form, even when you thought you had unloaded the form).

One good method to use, is to let the form load and show itself.

Create a public sub proceedure called something like "Display" in the form class code.

This proceedure then gets called from the "Main" sub in Module1:

Sub Main()
Dim frm As New Form1
Dim bIsError As Boolean'(if you do not want to use the error Raise method)

bIsError = frm.Display()

If bIsError Then
'An error has occured while initializing Form1
Goto EndApp
End If

set frm = nothing

Exit Sub

EndApp:

'Unload any open objects:
Set SomeObject = Nothing

dim frm As vb.form
for each frm in vb.Forms
unload frm
next frm
END

End Sub

In the form code window add something like this:

Option Explicit
'Notice: No use of the "New" keyword in the following statement
Private WithEvents m_rsADO As ADODB.Recordset

Public Function Display() As Integer
'Code here for initialization
Display=vbTrue 'Just in case the Me.Show method doesn't get called

'here is where the "New" keyword gets used
Set m_rsADO = New ADODB.Recordset
'Some other initialization code

'Some error:
If SomeError then
Unload Me
Else
Me.Show
Display=vbFalse
End If
End Function

Public Sub Form_Unload(Cancel As Integer)
'Clean up just to make sure

If m_rsADO.State = adStateOpen Then m_rsADO.Close

Set m_rsADO = Nothing
Set SomeOtherObject = Nothing
Set Form1 = Nothing
End Sub
[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Santhu has never replied to others suggestions.
why everyone is wasting time on this.
Please santhu, it is appropriate to reply to ur post

regards
John Philip *** Even the Best, did the Bad and Made the Best ***

John Philip
Software Programmer
JustDial Services, Mumbai
johnphilip@justdial.com
 
Hi all,
Please don't get irritated, I got an idea from all the reply. Actually I dont want to make network traffic for saying thanks. (I am telling in advance.) Any way thanks every one for participated in this discussion which brings more idea to me and the peoples.

-Regards
Santhakumar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top