Author Topic: Help getting a Basic Button to change to new Form  (Read 2010 times)

wimsettj

  • Newbie
  • *
  • Posts: 16
    • View Profile
Help getting a Basic Button to change to new Form
« on: September 23, 2014, 10:59:30 AM »
Hello everyone,

I'm still working on my automated bar & I am just about ready for full functional testing but I am having an issue with some of my VB code. Previously I used the following code to have a basic button change to form6 and transfer a string to a basic label on form6 using this code:

 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 LoadForm6(ByVal DrinkName As String)
        Dim oForm As New Form6
        oForm.SetDrinkName = DrinkName
        oForm.Selection.Text = DrinkName
        oForm.ShowDialog()
    End Sub

What I want to do now is use a Basic Button on form6 to change back to my main form. I tried the code below but it does nothing when I click the button:

Private Sub LoadMain()
        Dim oForm As New Main
    End Sub
 Private Sub ReturnDrink_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReturnDrink.Click
        LoadMain()
    End Sub

I tried adding in this line:  oForm.ShowDialog() It got me to the main form when I pressed the button but then caused the form change buttons on the main form to jump back to form6 instead of going to the correct form. What have I got wrong?

wimsettj

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Help getting a Basic Button to change to new Form
« Reply #1 on: September 28, 2014, 04:59:08 PM »
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.
Code: [Select]
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

Code: [Select]
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?

wimsettj

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Help getting a Basic Button to change to new Form
« Reply #2 on: October 03, 2014, 01:48:43 AM »
I got it figured out. I used Me.Hide() Is there a big difference between Hide() & Close()? Didn't know if it would make that big of a difference one way or the other.