Home > Mobile >  how to keep info on my main form when closing the secondary form
how to keep info on my main form when closing the secondary form

Time:10-02

I am trying to have the user select a code from a combo box that I need it to pass to my frmmenu.

Option Explicit On Imports System.Data.Odbc.OdbcConnection Imports System.Data.OleDb Imports Microsoft.VisualBasic

Public Class FrmMenu Friend PinLC As String, SwedgeLC As String, MonoLC As String, StrandLC As String, WireLC As String, TipLC As String, LenLC As String, TailLC As String, PackLC As String, LabelLC As String

then I have radio buttons that open different forms which each save info to each one of those strings above. We click on the form that will give me the SwedgeLC

Public Class FrmExtras Dim MREDLC As String, WREDLC As String, Swage As String

    Private Sub CboOptions2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CboOptions2.SelectedIndexChanged
Swage = UCase(CboOptions2.Text)
If Swage.Substring(0, 5) = "SWAGE" Then
      FrmMenu.SwedgeLC = "A"
End If
frmmenu.show()
me.close()

but on my frmmenu It doesnt keep the code "A" in this case, I never close the frmmenu I only just hide it. But when I go to show my codes on form1(frmmenu) its null. This I think happens becuase of when I go to open form 3, Form 2 will also open and that resets my code back to null. if I open form 4, form 3 and 2 open and resets both those codes to null. If I close the main form1, then the info isn't saved at all it only remembers the last form I picked the code for not all the others.

CodePudding user response:

    `Private Sub CboOptions2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CboOptions2.SelectedIndexChanged
Swage = UCase(CboOptions2.Text)
If Swage.Substring(0, 5) = "SWAGE" Then
      FrmMenu.SwedgeLC = "A"
End If
frmmenu.show()`

without the me.Close just try to comment that out. Then in form2 just add Me.Close in the close button

CodePudding user response:

Let's assume you are using default instances. In the frmMenu (I am calling it Form1) You should have a Friend field called SwedgeLC. It is Friend so it can be visible to all the classes in your project.

Public Class Form1

    Friend SwedgeLC As String

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Form2.Show()
        Close()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        MessageBox.Show(SwedgeLC)
    End Sub

End Class

Private Class Form2

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form1.SwedgeLC = "A"
        Form1.Show()
        Close()
    End Sub

End Class
  • Related