Get variable value in another visual basic form

0

I'm having a problem getting the value of a variável from another form . I tried to follow some macoratti tutorials but none of the 3 that had them worked there.

In this case, I have form1 and form2 , the second finds in a txt the value of a register for serial communication and needs this value in form1 to send as a message.

The code is quite large, so I thought it would be better not to post it. The link to the Macoratti page that I followed is esse

    
asked by anonymous 19.01.2017 / 17:48

1 answer

1

Create a public property in form2 and access it by form1 .

Example:

Public Partial Class form2
    Inherits Form
    Public Property Informacao() As String
        Get
            Return m_Informacao
        End Get
        Private Set
            m_Informacao = Value
        End Set
    End Property
    Private m_Informacao As String

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub buttonOk_Click(sender As Object, e As EventArgs)
        Informacao = "Alguma coisa"
        Me.Close()
    End Sub
End Class

Usage in form1

Dim frm As New Form2()
frm.Show()
Dim info As String = frm.Informacao
    
19.01.2017 / 18:15