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

Recommended Answers

All 4 Replies

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

@Pooja, is this the correct code? have you compiled the same?

@Bar-I - Yes it is working...make sure u write the correct form and label names

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.