Hello!

I'm very new to visual basic and I'm stuck at transfering the text from one label on a form to another via a button click event

I have 2 forms which I will call A and B. On form A I have a menu which when clicked brings up form B which has a button and a label. When I click on the button I want to transfer the text from that label to a label on form A.

I tried doing the following but have no luck, as form A doesn't update the information

    Public Sub okButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles okButton.Click
        Dim pie As New Puzzle
        If ListBox1.SelectedIndex = 0 Then
            label1.text = 50
            pie.label1.text = label1.text
            me.close()
        ElseIf Listbox1.SelectedIndex = 1 then
            label1.text = 75
            pie.label1.text = label1.text
            me.close()
        elseIf ListBox1.selectedIndex = 2 then
            label1.text = 100
            pie.label1.text = label1.text
            me.close
        End If
    End Sub

Edited 4 Years Ago by pritaeas: moved.

Firstly, this is .net code...

Public strThis As String

In your button click event -

strThis = Label1.Text

In form pie -

pie.label1.text = strThis

ur pie variable sets a new form every time so the value in the old form1 does not get updated

Comment the statement where u have declared the pie variable and just call the form name where u are declaring the variable to label
Like below

 'Dim pie As New Form1
          If ListBox1.SelectedIndex = 0 Then
               label1.text = 50
               Form1.Label1.Text = Label1.Text
               Me.close()
          ElseIf Listbox1.SelectedIndex = 1 Then
               label1.text = 75
               Form1.Label1.Text = Label1.Text
               Me.close()
          ElseIf ListBox1.selectedIndex = 2 Then
               label1.text = 100
               Form1.Label1.Text = Label1.Text
               Me.close()
          End If
This article has been dead for over six months. Start a new discussion instead.