I am getting this error "InvalidOperationException was unhandled" when switching from Form6 to my Main Form with a Form change button. It does not happen every time. Sometimes I can change 5 times in a row and other times I can't change once without the error.
My Form6 is opened by clicking any selection button on Forms 1 through 4. This action also transfers the name of the selection to a BasicLabel on From6. I don't know if the error is happening because the original form is still open in the background when I leave Form6 or if something else is going on.
This is what I'm using for Forms1-4
Public Class Form1
Private Sub Form_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
If components IsNot Nothing Then
Dim drv As AdvancedHMIDrivers.IComComponent
'*****************************
'* Search for comm components
'*****************************
For i As Integer = 0 To components.Components.Count - 1
If components.Components(i).GetType.GetInterface("AdvancedHMIDrivers.IComComponent") IsNot Nothing Then
drv = components.Components.Item(i)
'* Stop/Start polling based on form visibility
drv.DisableSubscriptions = Not Me.Visible
End If
Next
End If
End Sub
Private DrinkName As String
Private Sub LongIsland_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LongIsland.Click
DrinkName = "Long Island"
LoadForm6(DrinkName)
End Sub
Private Sub LongBeach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LongBeach.Click
DrinkName = "Long Beach"
LoadForm6(DrinkName)
End Sub
Private Sub LoadForm6(ByVal DrinkName As String)
Dim oForm As New Form6
oForm.SetDrinkName = DrinkName
oForm.Selection.Text = DrinkName
oForm.ShowDialog()
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
I tried adding in the Me.Close() because the Form was staying open in the background but it doesn't seem to work.
My Form6 code
Public Class Form6
Private Sub Form_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
If components IsNot Nothing Then
Dim drv As AdvancedHMIDrivers.IComComponent
'*****************************
'* Search for comm components
'*****************************
For i As Integer = 0 To components.Components.Count - 1
If components.Components(i).GetType.GetInterface("AdvancedHMIDrivers.IComComponent") IsNot Nothing Then
drv = components.Components.Item(i)
'* Stop/Start polling based on form visibility
drv.DisableSubscriptions = Not Me.Visible
End If
Next
End If
End Sub
Private DrinkName As String = ""
Public WriteOnly Property SetDrinkName As String
Set(ByVal value As String)
DrinkName = value
End Set
End Property
Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Any suggestions? I'm down to the wire on getting this project done on time.