Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error being thrown in Win 8.1 but not Win 7 nor Vistsa. Appears to be form closing event.

Posted on 2014-10-06
12
Medium Priority
?
397 Views
Last Modified: 2014-10-06
I have an app that is causing errors to be thrown on a couple of forms during the closing event. Th error is only showing up on Windows 8.1. Win 7 and Vista are not throwing the error.

Is this bad code where the older OS's were forgiving me or is it something else? The APP is in VB.net 2008. I can click continue on the error and the APP keeps running as intended.

Unfortunately my debugging is limited because I do not have Win 8.1.

    Private Sub Form7_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim frm As Form
        For Each frm In Me.MdiParent.MdiChildren
            If TypeOf frm Is Form2 Or TypeOf frm Is Form3 Or TypeOf frm Is Form4 Or TypeOf frm Is Form5 Or TypeOf frm Is Form6 Or TypeOf frm Is Form8 Or TypeOf frm Is Form9 Or TypeOf frm Is Form10 Or TypeOf frm Is Form11 Or TypeOf frm Is Form12 Or TypeOf frm Is Form13 Or TypeOf frm Is Form14 Or TypeOf frm Is Form15 Or TypeOf frm Is Form16 Or TypeOf frm Is Form17 Or TypeOf frm Is Form18 Or TypeOf frm Is Form19 Or TypeOf frm Is Form20 Or TypeOf frm Is Form21 Or TypeOf frm Is Form22 Or TypeOf frm Is Form23 Or TypeOf frm Is Form24 Or TypeOf frm Is Form25 Or TypeOf frm Is Form26 Or TypeOf frm Is Form27 Or TypeOf frm Is Form28 Then
                frm.Close()
            End If
        Next
    End Sub

Open in new window

0
Comment
Question by:PBLack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
12 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40365067
Can you post error raised?
0
 
LVL 40
ID: 40365071
If we do not know what the error is, we cannot answer.

Also, is it always happening on the same forms. Calling Close on these forms will also trigger the FormClosing error on them, so it might be where you have a problem. The code that you are showing should usually not give problems by itself.
0
 

Author Comment

by:PBLack
ID: 40365089
Hold on I will get them to send me a screen shot
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:PBLack
ID: 40365102
Message from error box

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at Microsoft.VisualBasic.PowerPacks.ShapeCollection.Dispose(Boolean disposing)
   at Microsoft.VisualBasic.PowerPacks.ShapeContainer.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at System.Windows.Forms.Control.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at System.Windows.Forms.Control.Dispose(Boolean disposing)
   at System.Windows.Forms.TabControl.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at System.Windows.Forms.Control.Dispose(Boolean disposing)
   at System.Windows.Forms.ContainerControl.Dispose(Boolean disposing)
   at System.Windows.Forms.Form.Dispose(Boolean disposing)
   at comstock_Compiler.Form7.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at System.Windows.Forms.Form.WmClose(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8009 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
comstock Compiler
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files%20(x86)/comstock/comstock%20Compiler/comstock%20Compiler.exe
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 8.0.0.0
    Win32 Version: 8.0.50727.8007 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.7905 (win9rel.050727-7900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8008 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8007 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8007 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8009 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8003 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
OpenNETCF.Desktop.Communication
    Assembly Version: 2.9.2244.24857
    Win32 Version: 2.9.2244.24857
    CodeBase: file:///C:/Program%20Files%20(x86)/comstock/comstock%20Compiler/OpenNETCF.Desktop.Communication.DLL
----------------------------------------
System.Data.SqlServerCe
    Assembly Version: 3.5.1.0
    Win32 Version: 3.5.8080.0
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Data.SqlServerCe/3.5.1.0__89845dcd8080cc91/System.Data.SqlServerCe.dll
----------------------------------------
System.Data
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8007 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Transactions
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8007 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.8007 (FX35W81RTMGDR.050727-8000)
    CodeBase: file:///C:/Windows/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
Microsoft.VisualBasic.PowerPacks.Vs
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.20911.1
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic.PowerPacks.Vs/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.PowerPacks.Vs.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

Open in new window


Screen shot
error.JPG
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 40365108
And you say it worked before? I focused on that statement and did not look further. But with the error message, it becomes evident.

You cannot remove elements from a collection when you loop with a for each. You have to do it in reverse with the "standard" for, replacing each instance of frm by Me.MdiParent.MdiChildren(x):

For x As Integer = Me.MdiParent.MdiChildren.Count-1 to 0 Step -1
     If TypeOf Me.MdiParent.MdiChildren(x) Is Form2 ... Then
          Me.MdiParent.MdiChildren(x).Close()
     End If
Next
0
 

Author Comment

by:PBLack
ID: 40365113
Yes it works 100% of the time on Vista and Win 7 installs. Today was the first time it was installed on Win 8.1. I will make the change you suggested and issue a fix, just in case.
0
 

Author Comment

by:PBLack
ID: 40365122
I closed the question too soon.

Me.MdiParent.MdiChildren.Count -  Error: 'Count' is not a member of 'System.Array'
0
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40365125
Try changing the For to :

For x = 0 To (Me.MdiChildren.Length) - 1
0
 

Author Comment

by:PBLack
ID: 40365145
@samo4fun - thank you
0
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40365148
Just thank you? Kidding ;)   glad to help ...
0
 

Author Comment

by:PBLack
ID: 40365199
Well I wish I could give you some points but stupid me closed it.
0
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40365201
No biggie...
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

715 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