Ok, so I figured out what my problem is but not how to fix it. I am going from one of my "Drink Selection" Forms to my "Drink Mixing" Form. When I do this I am not actually closing the first form and opening a second. The "Selection" form is staying open and the "Mixing" form is opening over the top of it. Then when I try and use the same type of code to move to a new form it gets confused and all my form buttons after the 2nd form change send me back to my "mixing" form.
What I need to do is have my "Return to Main Form" basic button close the current "Mixing" form, so I am back on the still open "Selection" form. Here is the code I'm currently using. Form1 is my "Selection Form" and Form6 is my "Mixing Form" I have removed the bit of code that has been giving me fits so there would be a clean starting point for a solution.
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()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
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
Private Sub ReturnDrink_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReturnDrink.Click
End Sub
End Class
"ReturnDrink" is the basic button that tells the PLC to clear the current drink recipe. I also need it to close the current form6. Any suggestions?