PC Review


Reply
Thread Tools Rate Thread

closing a form before it loads.

 
 
smhaig
Guest
Posts: n/a
 
      2nd Mar 2004
In a vb 6 app in the activate event I was able to do some
testing and if something failed, I was able to exit the
form and return to the caller form.

I have tried everything and searched web but can't find
way to do this in vb.net. Some say throw an exception,
but I don't know what exception to throw and how to exit
from the catch to return to the caller form.


thanks for any help


 
Reply With Quote
 
 
 
 
Big D
Guest
Posts: n/a
 
      2nd Mar 2004
When creating a new instance of your form you could call a function which
performs the test from the calling form (calling class) so you would have:

dim fooForm as new SuperForm()
if fooForm.passesTests then
fooForm.show()
else
fooForm.dispose()
end if

Or something like that. Is this what you are asking? Sorry if I missed the
point.

-MC D
"smhaig" <(E-Mail Removed)> wrote in message
news:5f8801c400a5$a9a4f320$(E-Mail Removed)...
> In a vb 6 app in the activate event I was able to do some
> testing and if something failed, I was able to exit the
> form and return to the caller form.
>
> I have tried everything and searched web but can't find
> way to do this in vb.net. Some say throw an exception,
> but I don't know what exception to throw and how to exit
> from the catch to return to the caller form.
>
>
> thanks for any help
>
>



 
Reply With Quote
 
smhaig
Guest
Posts: n/a
 
      2nd Mar 2004
Hi I did not go into it, I admit, as it is complicated.
I am actually putting info on all open forms in a list
collection of classes each of which holds info on each
form (such as the handle and the name of the form). In
the activate code I check to see if this form info class
is in the collection (it is put in the list in the
caller form between f = new form2 and f.show). If it is
not, then the form does not load.

Since I do not know anything about what goes on behind
the scenes I cannot say whether your code would work.

Hope that helps.

>-----Original Message-----
>When creating a new instance of your form you could call

a function which
>performs the test from the calling form (calling class)

so you would have:
>
>dim fooForm as new SuperForm()
>if fooForm.passesTests then
> fooForm.show()
>else
> fooForm.dispose()
>end if
>
>Or something like that. Is this what you are asking?

Sorry if I missed the
>point.
>
>-MC D


 
Reply With Quote
 
Stephen Muecke
Guest
Posts: n/a
 
      3rd Mar 2004
smhaig,

In each form, you can shadow the show method and determine if it should be
shown, or if an already open instance should be activated
The following example assumes you have a singleton collection class
FormCollection that maintains your 'open' forms
Also note that the form needs to be removed from the collection when the
form is closed

Public Class myForm

Private Shadows Sub Show()
'Check an instance of this form is not already open
Dim frm As Form
For each frm in FormCollection.GetInstance
If TypeOf frm is myForm Then
'The document is already open, so dispose this instance
Me.Dispose()
'Activate the original instance
frm.Activate()
'Exit the sub
Exit Sub
End If
Next
'Add the form to the collection
FormCollection.GetInstance.Add(Me)
'Show the form
MyBase.Show()
End Sub

Stephen


"smhaig" <(E-Mail Removed)> wrote in message
news:30e701c400ab$fb6a6cc0$(E-Mail Removed)...
> Hi I did not go into it, I admit, as it is complicated.
> I am actually putting info on all open forms in a list
> collection of classes each of which holds info on each
> form (such as the handle and the name of the form). In
> the activate code I check to see if this form info class
> is in the collection (it is put in the list in the
> caller form between f = new form2 and f.show). If it is
> not, then the form does not load.
>
> Since I do not know anything about what goes on behind
> the scenes I cannot say whether your code would work.
>
> Hope that helps.
>
> >-----Original Message-----
> >When creating a new instance of your form you could call

> a function which
> >performs the test from the calling form (calling class)

> so you would have:
> >
> >dim fooForm as new SuperForm()
> >if fooForm.passesTests then
> > fooForm.show()
> >else
> > fooForm.dispose()
> >end if
> >
> >Or something like that. Is this what you are asking?

> Sorry if I missed the
> >point.
> >
> >-MC D

>



 
Reply With Quote
 
Guest
Posts: n/a
 
      3rd Mar 2004
I have a few questions on this last post. From where is
this called? From the caller form or the called form
that needs to be checked. I know from testing that I
could not use dispose() in the activate or load event of
the form I want to dispose. So I am not sure where this
goes.The checking of the collection stuff I have in a
module and I return a boolean and from that boolean
decide whether to continue with the load or not. So the
question is where does your code get placed and who calls
it.

The code I am having problems with could be used in many
situations, not just mine. Its really a question of
closing a form before a load for whatever reason.



>-----Original Message-----
>smhaig,
>
>In each form, you can shadow the show method and

determine if it should be
>shown, or if an already open instance should be activated
>The following example assumes you have a singleton

collection class
>FormCollection that maintains your 'open' forms
>Also note that the form needs to be removed from the

collection when the
>form is closed
>
>Public Class myForm
>
>Private Shadows Sub Show()
> 'Check an instance of this form is not already open
> Dim frm As Form
> For each frm in FormCollection.GetInstance
> If TypeOf frm is myForm Then
> 'The document is already open, so dispose this

instance
> Me.Dispose()
> 'Activate the original instance
> frm.Activate()
> 'Exit the sub
> Exit Sub
> End If
> Next
> 'Add the form to the collection
> FormCollection.GetInstance.Add(Me)
> 'Show the form
> MyBase.Show()
>End Sub
>
>Stephen
>
>
>"smhaig" <(E-Mail Removed)> wrote in

message
>news:30e701c400ab$fb6a6cc0$(E-Mail Removed)...
>> Hi I did not go into it, I admit, as it is complicated.
>> I am actually putting info on all open forms in a list
>> collection of classes each of which holds info on each
>> form (such as the handle and the name of the form).

In
>> the activate code I check to see if this form info

class
>> is in the collection (it is put in the list in the
>> caller form between f = new form2 and f.show). If it

is
>> not, then the form does not load.
>>
>> Since I do not know anything about what goes on behind
>> the scenes I cannot say whether your code would work.
>>
>> Hope that helps.
>>
>> >-----Original Message-----
>> >When creating a new instance of your form you could

call
>> a function which
>> >performs the test from the calling form (calling

class)
>> so you would have:
>> >
>> >dim fooForm as new SuperForm()
>> >if fooForm.passesTests then
>> > fooForm.show()
>> >else
>> > fooForm.dispose()
>> >end if
>> >
>> >Or something like that. Is this what you are asking?

>> Sorry if I missed the
>> >point.
>> >
>> >-MC D

>>

>
>
>.
>

 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      3rd Mar 2004
* "smhaig" <(E-Mail Removed)> scripsit:
> In a vb 6 app in the activate event I was able to do some
> testing and if something failed, I was able to exit the
> form and return to the caller form.
>
> I have tried everything and searched web but can't find
> way to do this in vb.net. Some say throw an exception,
> but I don't know what exception to throw and how to exit
> from the catch to return to the caller form.


Better: Don't even instantiate the class. For example, you can add
a public shared method to the class which returns the reference to the form:

\\\
Public Shared Function Create() As MyForm
If ... Then
Return New MyForm()
Else
Return Nothing ' :-).
End If
End Function
///

Usage:

\\\
Dim f As MyForm = MyForm.Create()
If f Is Nothing Then
...
Else
...
End If
///

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
2007 Form Design loads 2003 Form JoeRob Microsoft Outlook Form Programming 13 14th Jan 2011 09:56 PM
Showing form , closing login form but not closing app, how Bob Microsoft VB .NET 3 21st Dec 2005 07:54 PM
Closing event in a MID Child form I don't know if the child form is closing or the main form is closing **Developer** Microsoft C# .NET 1 19th Oct 2005 04:51 PM
Calling inherited form - form loads and is a creature somewhat lik =?Utf-8?B?bmlkZ2V0?= Microsoft C# .NET 2 12th Apr 2005 04:22 PM
Multiple OutputTo (Called on Closing Form) Fails on Closing Database John Andrews Microsoft Access Macros 3 21st May 2004 08:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:44 AM.