Results 1 to 10 of 10

Thread: [RESOLVED] Me.FormClosing ( Designer: Call Stack Error )

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    19

    Resolved [RESOLVED] Me.FormClosing ( Designer: Call Stack Error )

    First I apologize for the long explanation here, if you don't wish to read through all of this explanation, skip to Problem: in bold text.

    I wanted to explain everything just in case you needed more information, so I'm providing it now so I don't have to answer as many questions later.

    Personal Information:
    I am somewhat of a new programmer. I have been learning for over a year, doing research online, and reading a ton of books. I've come a long way and am now working as a programmer at my place of work, but by no means do I consider myself an advanced programmer.

    I am developing an app that writes to an XML file and that's what I'm using to store information. This is just a test app that I'm building to increase my skills and knowledge.

    Information:
    I created a Subroutine that checks if a Form is being closed by pressing the X by the Maximize and Minimize buttons. If the Form is being closed by the user, then I need to know. The reason I need to know is that when a new department is being created (each department that's created must have an Admin Account associated with the Department so that changes can be made for each user that follows and is created for each department) I can then ask the user if they wish to cancel the creation of the department so that it can then be removed (the department has to be created before I can write the information to the XML, so the file has already been saved with the creation of the new department). So if they select Yes on the MessageBox then it calls to the Form that has the department information (department name is selected and I've greyed out the buttons and ListBox so no changes can be made and the department doesn't lose focus. I've also disabled the ability to close the Form by pressing the X or Exit button) to remove the Department and subtract (-1) from the NextUID Number in the XML file (this is how I generate Unique Identification Numbers for each Department and User Account being created.

    I am using a FormClosing Subroutine to handle Booleans for the Forms that create the New Department and User Account. If they're open on the screen, I'm not allowing the Form that has the list of all departments to close. I'm doing this because in order to remove the New Department in the Event that the user doesn't wish to create an Admin Account I need to remove the New Department and I cannot do that if the Form that holds the list of all of the Departments is closed as I'm removing the account based on which department is selected on that Form. I cannot do that if the Form is accidentally or purposefully closed by the User who's logged in (Admin Rights).

    Problem: When I add the Subroutine and try to look at the [Design] of the Form, I recieve an Error.

    Error:

    Instances of this error (1)

    1. Hide Call Stack
    at Microsoft.VisualStudio.Shell.Design.Serialization.CodeDom.CodeDomEventBindingService.ValidateMethodN ame(String methodName)
    at System.ComponentModel.Design.EventBindingService.EventPropertyDescriptor.SetValue(Object component, Object value)
    at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAttachEventStatement(IDe signerSerializationManager manager, CodeAttachEventStatement statement)
    at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSeria lizationManager manager, CodeStatement statement)

    Help with this error

    MSDN Help

    Forum posts about this error

    Search the MSDN Forums for posts related to this error

    It allows me to [Ignore & Continue], but then receive a MessageBox that says:

    "[Microsoft Visual Studio] Ignoring these exceptions will put the designer in an unstable state that could result in the loss of controls. Do you want to continue?"

    I selected No for now.

    Can someone please take a look at my code and see if there's a better way o

    Code:
    Code:
        
        Private Sub DeptSelection(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    
            If e.CloseReason = CloseReason.UserClosing Then
                '--Need to notify DeptSelection.vb that form was closed without saving the creation of an Admin Account for the New Department that was just created
                
                If UserApplicationFormAtts.OpenStatus = True Or DeptEditInfo.OpenStatus = True Then
                    e.Cancel = True
                Else
                    e.Cancel = False
                End If
            End If
    
        End Sub
    I thank everyone who can help me out and took the time to read this post.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    19

    Re: Me.FormClosing ( Designer: Call Stack Error )

    I was able to find more information online and was able to fix this problem. Posting this reply for anyone who may be having this same issue.

    Here's the Code:

    Code:
        ' **************************************************************************************
        ' *                                                                                                                                                        *
        ' *  Form Closing; Don't Allow Form to Close If UserApplicationFormAtts Form Is Open..                                         *
        ' *						 [2023 02 06]			                                                                *
        ' *                                                                                                                                                        *
        ' **************************************************************************************
        
            Public Class frmExplorer
            Public Event FormClosing(sender As Object, e As FormClosingEventArgs)
    
            Private Sub frmExplorer_DeptSelection(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    
                If e.CloseReason = CloseReason.UserClosing Then
                    'Need to notify DeptSelection.vb that form was closed without saving
                    'Main.OpenForm = "Canceled"
                    If UserApplicationFormAtts.OpenStatus = True Or DeptEditInfo.OpenStatus = True Then
                        e.Cancel = True
                    Else
                        e.Cancel = False
                    End If
                End If
    
            End Sub
        End Class

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,053

    Re: Me.FormClosing ( Designer: Call Stack Error )

    That looks really weird. Is this a standard Windows Forms project? And is this a standard Form? It sure looks like the answer to both of those questions is Yes.

    If so, I wouldn't think you'd even be able to declare that event. There's already a FormClosing event, and you had it in your previous post. Declaring a new event that is the same as an existing event shouldn't even be allowed. So...there's something decidedly off about that solution, or your installation, or something like that.

    I just tried adding such an event to a form and the compiler complained that my newly declared event conflicted with the same event in the base class. So, yeah, there's something wrong there. You shouldn't even be allowed to do what you are doing, if all was right with your project.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    19

    Re: Me.FormClosing ( Designer: Call Stack Error )

    Quote Originally Posted by Shaggy Hiker View Post
    That looks really weird. Is this a standard Windows Forms project? And is this a standard Form? It sure looks like the answer to both of those questions is Yes.

    If so, I wouldn't think you'd even be able to declare that event. There's already a FormClosing event, and you had it in your previous post. Declaring a new event that is the same as an existing event shouldn't even be allowed. So...there's something decidedly off about that solution, or your installation, or something like that.

    I just tried adding such an event to a form and the compiler complained that my newly declared event conflicted with the same event in the base class. So, yeah, there's something wrong there. You shouldn't even be allowed to do what you are doing if all was right with your project.

    Ok so it just appeared to have fixed my problem, because I saw that the Form came back and I was able to edit it, but then the code didn't work on my second post for the event/action.

    I changed it back to the original and it's working just fine, but when I go into the designer, it won't allow me to view it due to the error. The code in the first post works just fine as far as running the app and doing exactly what I'm asking of it. My real question is if I should be doing something different with the code or putting it somewhere else.

    Or can I leverage when a user is closing another form, but to tell another form that it's closing? This was the only way I could figure out the solution to my problem, but only created another problem, which doesn't really appear to be a problem, except for the fact i'm basically overwriting the formclosing and utilizing it in my own way and VS doesn't seem to like it in the designer... can I add something to the designer code to allow it?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    19

    Re: Me.FormClosing ( Designer: Call Stack Error )

    Quote Originally Posted by RussellBishopSr View Post
    Ok so it just appeared to have fixed my problem, because I saw that the Form came back and I was able to edit it, but then the code didn't work on my second post for the event/action.

    I changed it back to the original and it's working just fine, but when I go into the designer, it won't allow me to view it due to the error. The code in the first post works just fine as far as running the app and doing exactly what I'm asking of it. My real question is if I should be doing something different with the code or putting it somewhere else.

    Or can I leverage when a user is closing another form, but to tell another form that it's closing? This was the only way I could figure out the solution to my problem, but only created another problem, which doesn't really appear to be a problem, except for the fact i'm basically overwriting the formclosing and utilizing it in my own way and VS doesn't seem to like it in the designer... can I add something to the designer code to allow it?
    Name:  Formclosing.jpg
Views: 39
Size:  12.0 KB

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    19

    Re: Me.FormClosing ( Designer: Call Stack Error )

    Quote Originally Posted by RussellBishopSr View Post
    Name:  Formclosing.jpg
Views: 39
Size:  12.0 KB
    Alright, I finally figured this out. It was something I overlooked and that was part of the Subroutine Name. DeptSelection_FormClosing() vs. DeptSelection(). It absolutely has to have _FormClosing in order to function properly. It's now working great and I have my Designer back. Now I am able to tell another form when it's closing so that I can enable all of the objects. Thanks for your help and for taking the time to read this.

    Marking this as solved.
    Code:
            Private Sub DeptSelection_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    
            If e.CloseReason = CloseReason.UserClosing Then
                '--Need to notify DeptSelection.vb that form was closed without saving the creation of an Admin Account for the New Department that was just created
                
                If UserApplicationFormAtts.OpenStatus = True Or DeptEditInfo.OpenStatus = True Then
                    e.Cancel = True
                Else
                    e.Cancel = False
                End If
            End If
    
        End Sub

  7. #7
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,112

    Re: Me.FormClosing ( Designer: Call Stack Error )

    Quote Originally Posted by RussellBishopSr View Post
    Alright, I finally figured this out. It was something I overlooked and that was part of the Subroutine Name. DeptSelection_FormClosing() vs. DeptSelection(). It absolutely has to have _FormClosing in order to function properly. It's now working great and I have my Designer back. Now I am able to tell another form when it's closing so that I can enable all of the objects. Thanks for your help and for taking the time to read this.

    Marking this as solved.
    Code:
            Private Sub DeptSelection_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    
            If e.CloseReason = CloseReason.UserClosing Then
                '--Need to notify DeptSelection.vb that form was closed without saving the creation of an Admin Account for the New Department that was just created
                
                If UserApplicationFormAtts.OpenStatus = True Or DeptEditInfo.OpenStatus = True Then
                    e.Cancel = True
                Else
                    e.Cancel = False
                End If
            End If
    
        End Sub
    Yeaaaa.... no. The problem WAS the function name ... but not because it didn't have _FormClosing ... the name of the function is irrelevant ... unless you happen to name it exactly the same as your form name... THAT was the problem. As long as it has the Handles clause... the name of the sub can be anything you want (excerpting the form name, or the name of any keyword, or the name of a variable in use.)

    This works:
    Code:
            Private Sub MyFormIsClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    
            If e.CloseReason = CloseReason.UserClosing Then
                '--Need to notify DeptSelection.vb that form was closed without saving the creation of an Admin Account for the New Department that was just created
                
                If UserApplicationFormAtts.OpenStatus = True Or DeptEditInfo.OpenStatus = True Then
                    e.Cancel = True
                Else
                    e.Cancel = False
                End If
            End If
    
        End Sub
    and this
    Code:
            Private Sub qwerty(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    
            If e.CloseReason = CloseReason.UserClosing Then
                '--Need to notify DeptSelection.vb that form was closed without saving the creation of an Admin Account for the New Department that was just created
                
                If UserApplicationFormAtts.OpenStatus = True Or DeptEditInfo.OpenStatus = True Then
                    e.Cancel = True
                Else
                    e.Cancel = False
                End If
            End If
    
        End Sub

    and this:
    Code:
            Private Sub Quijibo(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    
            If e.CloseReason = CloseReason.UserClosing Then
                '--Need to notify DeptSelection.vb that form was closed without saving the creation of an Admin Account for the New Department that was just created
                
                If UserApplicationFormAtts.OpenStatus = True Or DeptEditInfo.OpenStatus = True Then
                    e.Cancel = True
                Else
                    e.Cancel = False
                End If
            End If
    
        End Sub
    And htis too:
    Code:
            Private Sub SomeLongDrawnOutNAmeForASubThatIsRediculouButStillWorks(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    
            If e.CloseReason = CloseReason.UserClosing Then
                '--Need to notify DeptSelection.vb that form was closed without saving the creation of an Admin Account for the New Department that was just created
                
                If UserApplicationFormAtts.OpenStatus = True Or DeptEditInfo.OpenStatus = True Then
                    e.Cancel = True
                Else
                    e.Cancel = False
                End If
            End If
    
        End Sub
    As long as the Handles clause is there and the sub signature matches the event you're handling ... you're good.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    19

    Re: Me.FormClosing ( Designer: Call Stack Error )

    I pulled an all-nighter the last 2 nights (long story) and was tired this morning, but on the way to work, I was thinking about it and realized that it wasn't because I didn't have _FormClosing (which didn't make any sense to me at the time, due to fatigue most likely). I came to the conclusion that the form name was the same as the Subroutine. This is where it was breaking in the Designer. This is funny because VS (2017) didn't even redline it or anything. It allowed it to be used and it actually was functioning, yet the Designer caught it and had next to zero explanation as to why.

    All of my research came up with nothing. Anyway, this is still useful to somebody out there I'm sure for utilizing a simple Boolean (OpenStatus = True or False) based on a String to notify that form of which form opened it. This way I can capture what state the App is currently in.

    Again thanks for all of your guy's help, I greatly appreciate you taking the time out of your day to respond.

    If you have any tips for handling this any better, I'm definitely all ears! I don't have any programmer friends around here to help guide me, so all of my learning has been online and through books. That's why I decided to join VB Forums because a lot of my answers were due to people helping others on this platform.

    I am more than grateful and open to getting criticism and or advice! And Microsoft's website (https://learn.microsoft.com) usually has C# code and not VB, which is frustrating because I can never figure out how to make it work for vb.NET, especially with all the { } {{{ {} {{{}}} LMAO!

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,053

    Re: [RESOLVED] Me.FormClosing ( Designer: Call Stack Error )

    You get some {} in VB, as well. Just create an object while setting the properties during creation. Still, it's not nearly as much as in C#. That language is more bracing.

    There is the obvious comment. I didn't make it because it was...wait for it....obvious: An XML file isn't a great solution for this. Since it was just for training/practice/testing, then it would make sense, but ultimately you will will need a database for this.

    A much simpler point is that this is sub-optimal:

    Code:
    If UserApplicationFormAtts.OpenStatus = True Or DeptEditInfo.OpenStatus = True Then
                        e.Cancel = True
                    Else
                        e.Cancel = False
                    End If
    That should be written:
    Code:
    e.cancel = UserApplicationFormAtts.OpenStatus  OrElse DeptEditInfo.OpenStatus
    There are several changes in that.

    1) Checking whether a Boolean '=True' is pointless. It will equal True if it IS True, otherwise it will not equal True, so the check is extraneous.
    2) OrElse (along with AndAlso) is superior to Or in almost every case. OrElse will short circuit. If the first is true, the second isn't even evaluated, because the truth of the whole statement is already known. That's simply more efficient. You need to use Or for bit manipulation, and the exceedingly rare cases where you MUST evaluate both halves...which usually means you are making use of a side effect, which has it's own issues.
    3) Don't use a conditional when one is not needed. In this case, you are setting a Boolean property, so the evaluation is all that matters.
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    19

    Re: [RESOLVED] Me.FormClosing ( Designer: Call Stack Error )

    Thank you very much I will go use that!

    I'm using XML because my employer uses XML, so I'm familiarizing myself with how to use it in order to get better at my job.

    Thanks for the examples!!!

Tags for this Thread

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