Take variable value in another basic visual form

Asked

Viewed 902 times

0

I’m having a problem getting the value of a variável other’s form. I tried to follow some tutorials of macoratti but none of the 3 that had there worked.

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

The code is pretty big, so I thought it best not to post it.
The link to the Macoratti page I followed is that

1 answer

1


Create a public property on form2 and access it through 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

Use in form1

Dim frm As New Form2()
frm.Show()
Dim info As String = frm.Informacao
  • It worked, I think I was inserting in the wrong place the declaration of the variable. Thank you very much jbueno

Browser other questions tagged

You are not signed in. Login or sign up in order to post.