?
Solved

error on Me.FormClosing

Posted on 2006-05-18
31
Medium Priority
?
294 Views
Last Modified: 2008-02-07
Hello,
I have this code in module.vb but why do I get this error on Me.FormClosing
 

   Private FormIsClosing As Boolean = False
    Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        FormIsClosing = True
    End Sub
0
Comment
Question by:aplelois
  • 15
  • 8
  • 3
  • +2
31 Comments
 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 16715150
what is the error description u get ?
and in which line u get the error ?
0
 

Author Comment

by:aplelois
ID: 16715161
Error      1      'Handles' in modules must specify a 'WithEvents' variable qualified with a single identifier.

then I double click it and it takes me to -> Me.FormClosing
0
 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 16715188
there is no formisclosing event, use closing event


 Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
           FormIsClosing = True

    End Sub
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:aplelois
ID: 16715203
Error      1      'Handles' in modules must specify a 'WithEvents' variable qualified with a single identifier.

then I double click it and it takes me to -> MyBase.Closing
0
 
LVL 6

Expert Comment

by:carmodyk
ID: 16715317
What exactly are you trying to do in regards to a form closing?  Are you sending a value to another function when a form closes?  Are you opening the form using another a button or something like that?
0
 

Author Comment

by:aplelois
ID: 16715323
this is where im using FormIsClosing in the module.vb

    Private Sub Delay(ByVal DelayInSeconds As Integer)
        Dim ts As TimeSpan
        Dim targetTime As DateTime = DateTime.Now.AddSeconds(DelayInSeconds)
        Do
            ts = targetTime.Subtract(DateTime.Now)
            Application.DoEvents()
            System.Threading.Thread.Sleep(50)
        Loop While (Not FormIsClosing) AndAlso (ts.TotalSeconds > 0)
    End Sub
0
 

Author Comment

by:aplelois
ID: 16715330
the loop keeps going when I close the app..
the app keeps running in the background.
0
 
LVL 6

Expert Comment

by:carmodyk
ID: 16715339
Just for laughs,

Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
           FormIsClosing = True
frmMain.dispose()

    End Sub
0
 

Author Comment

by:aplelois
ID: 16715350
Error     1     'Handles' in modules must specify a 'WithEvents' variable qualified with a single identifier.

MyBase.Closing
0
 
LVL 6

Expert Comment

by:carmodyk
ID: 16715366
How is the form started?  Is it the startup form?
0
 

Author Comment

by:aplelois
ID: 16715387
with a button
0
 
LVL 6

Expert Comment

by:carmodyk
ID: 16715424
Try this:

1. Set your Private FormIsClosing boolean to Public instead of Private

Public FormIsClosing As Boolean = False
    Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        FormIsClosing = True
    End Sub

In your Button Code do the following.

 Dim objOpenForm As frmMain
      objOpenForm = New frmMain
       With objOpenForm
            .Owner = Me
            .ShowDialog()
            if objOpenForm.FormIsClosing = True then
               'Stop Function
            End if
      objOpenForm.Dispose()



0
 

Author Comment

by:aplelois
ID: 16715452
Error      2      'FormIsClosing' is not a member of 'email.frmMain'.      
the -> objOpenForm.FormIsClosing
0
 
LVL 6

Expert Comment

by:carmodyk
ID: 16715491
Hmmm....OK, I guess your FormIsClosing is part of your main form.  Try this:

In your Button Code do the following.

 Dim objOpenForm As frmMain
      objOpenForm = New frmMain
       With objOpenForm
            .Owner = Me
            .ShowDialog()
           FormIsClosing = True  
      objOpenForm.Dispose()
0
 

Author Comment

by:aplelois
ID: 16715513
Error      2      'With' must end with a matching 'End With'.

-> With objOpenForm

so I added and end with at the end like this

        Dim objOpenForm As frmMain
        objOpenForm = New frmMain
        With objOpenForm
            .Owner = Me
            .ShowDialog()
            FormIsClosing = True
            objOpenForm.Dispose()
        End With

but this error keeps coming out
Error      1      'Handles' in modules must specify a 'WithEvents' variable qualified with a single identifier.
-> Me.FormClosing
0
 
LVL 6

Expert Comment

by:carmodyk
ID: 16715576
OK, I'm going to go to bed soon, so lets try to iron this out:  What is the overall thing you are trying to do.  I'm guessing your trying to accomplish some sort of stop watch thing where as a form is open, the time it is open matters somewhere?  Are you trying to change the display or a label of one form while another form is open?
0
 

Author Comment

by:aplelois
ID: 16715611
ok, I moved everything from the module into the frmMain.vb and now I dont get any error
but when I close the app it still running!!
0
 
LVL 6

Expert Comment

by:carmodyk
ID: 16715622
Where is the App? in the Module?
0
 

Author Comment

by:aplelois
ID: 16715629
no, in frmMain.vb
0
 
LVL 6

Expert Comment

by:carmodyk
ID: 16715669
I can only assume that you are talking about your Do While loop still running right? Try taking out the AndAlso part

 Private Sub Delay(ByVal DelayInSeconds As Integer)
        Dim ts As TimeSpan
        Dim targetTime As DateTime = DateTime.Now.AddSeconds(DelayInSeconds)
        Do
            ts = targetTime.Subtract(DateTime.Now)
            Application.DoEvents()
            System.Threading.Thread.Sleep(50)
        Loop While (Not FormIsClosing)    
 End Sub
0
 

Author Comment

by:aplelois
ID: 16715723
now the app doesnt even work
0
 
LVL 9

Expert Comment

by:sk33v3
ID: 16718621
ok in your original loop put the following if statement as the first line within the loop

If FormisClosing then Exit Do

0
 

Author Comment

by:aplelois
ID: 16718658
can you show me the complete code please?
0
 
LVL 9

Expert Comment

by:sk33v3
ID: 16718699
Private Sub Delay(ByVal DelayInSeconds As Integer)
        Dim ts As TimeSpan
        Dim targetTime As DateTime = DateTime.Now.AddSeconds(DelayInSeconds)
        Do
            If FormisClosing then Exit Do
            ts = targetTime.Subtract(DateTime.Now)
            Application.DoEvents()
            System.Threading.Thread.Sleep(50)
        Loop While (ts.TotalSeconds > 0)
    End Sub
0
 

Author Comment

by:aplelois
ID: 16718747
it keeps running in the background
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16718775
Public Class frmMain

    Private FormIsClosing As Boolean = False

    Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        FormIsClosing = True
    End Sub

    Private Sub Delay(ByVal DelayInSeconds As Integer)
        Dim ts As TimeSpan
        Dim targetTime As DateTime = DateTime.Now.AddSeconds(DelayInSeconds)
        Do
            If FormIsClosing Then Exit Sub
            ts = targetTime.Subtract(DateTime.Now)

            If FormIsClosing Then Exit Sub
            Application.DoEvents()

            If FormIsClosing Then Exit Sub
            System.Threading.Thread.Sleep(50)

        Loop While (Not FormIsClosing) AndAlso (ts.TotalSeconds > 0)
    End Sub

End Class
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 16718828
With regards to this question:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21855541.html

You also need to make the code drop out of your cmdMail_Click() sub in the same way we are doing in the Delay() sub.  So before you go navigating off to another page, you need to do the checks:

    Private Sub cmdMail_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdMail.Click
        On Error Resume Next
        Dim i As Integer
        Dim txtOne, txtTwo As Object

            Call WebBrowser1.Navigate(New System.Uri("http://www.email.com"))

            While (Not FormIsClosing) AndAlso (WebBrowser1.ReadyState <> System.Windows.Forms.WebBrowserReadyState.Complete)
                System.Windows.Forms.Application.DoEvents()
            End While

            Delay(2)
            If FormIsClosing Then Exit Sub

            With WebBrowser1.Document.DomDocument
                txtOne = .GetElementsByName("email")(0)
                txtTwo = .GetElementsByName("pass")(0)

                txtOne.Value = "email@isp.com"
                txtTwo.Value = "pass"

                .Forms(1).submit()
            End With

            While (Not FormIsClosing) AndAlso (WebBrowser1.ReadyState <> System.Windows.Forms.WebBrowserReadyState.Complete)
                System.Windows.Forms.Application.DoEvents()
            End While

            Delay(5)
            If FormIsClosing Then Exit Sub

            ' more code if necessary....
 
    End Sub
0
 

Author Comment

by:aplelois
ID: 16718850
It keeps running
0
 
LVL 9

Expert Comment

by:sk33v3
ID: 16718897
If it continues running my guess is that you have some other piece of code running and its not the loop you posted. What else do you have this thing doing?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16718916
Well it's not the Delay() sub thats keeping it open.

If you've added the code as I've described here: http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21856334.html#16718775

The the Delay() sub will properly drop out of it's loop and allow the application to close.

It is most likely the WebBrowser control still trying to navigate somewhere and your loop is keeping the code from exiting:

           While (WebBrowser1.ReadyState <> System.Windows.Forms.WebBrowserReadyState.Complete)
                System.Windows.Forms.Application.DoEvents()
            End While

Or something else is keeping it from closing...
0
 

Author Comment

by:aplelois
ID: 16719004
this did the trick

Delay(5)
If FormIsClosing Then Exit Sub

thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question