0

I have the problem to retreive the string from one form to another. here is my code: What's wrong with this?

Public Class Form3

    Dim unit As String

    Public itmname As String
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim obj1 As New Form4
        itmname = tb1.Text
        MessageBox.Show(itmname)
        obj1.Label1.Text = itmname
        obj1.Show()

    End Sub
End Class
Public Class Form4
 Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With Form3
            MessageBox.Show("item name:" + .itmname)
           Label1.Text = .itmname
        End With
    End Sub
End Class
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
user993444
  • 53
  • 3
  • 9

1 Answers1

0

You shouldn't have to do any special code in Form4 to set the value. you already set the textbox value from from3's button click event. Setting again is just overwriting it with a blank value from a newly instantiated form. Just clear all the code you have listed in Form4's load event and it should work.

Bradley Uffner
  • 16,641
  • 3
  • 39
  • 76
  • I need one more clarification. Now I am calling the obj1.Show() in Form3, Supose I have assign the value of label of Form4 in Form3 & I want to call obj1.show in form2, then What code I have to use in Form2? Pls reply – user993444 Dec 02 '11 at 09:07
  • If you create an event `public event ValueChanged(Value as string)` on Form4, and raise it using `RaiseEvent ValueChanged(label1.text)` when the text has changed, anything listening to that event will be able to get a notification of it changing. It's a little hard to follow your example because of the variable and type names you choose. If I didn't understand your 2nd question let me know and I'll try to clarify. – Bradley Uffner Dec 02 '11 at 12:19
  • I am using menu items (like itm1, itm2, itm3 etc....) in Form1. If I click on itm1, it opens the new Form named Form2 and it has one textbox tb1 and one ok button. if I type somethimg on tb1 & click on OK, then that value should added to Combobox cb1 list which is in Form3. If I click on itm2 then the Form3 should open with the Combobox cb1 which contains all the added items in the list. this is my actual flow. pls help me – user993444 Dec 05 '11 at 06:08
  • If you pass a reference to one form from another you can use that reference to update controls on that other form. Lets pretend you have Forms FormA, FormB and FormC. If FormA opens FormB, and FormB needs to access something on FormC, then FormA can pass a reference to FormC into FormB via a property `Public Property frmC as FormC`. From inside FormB you can do stuff like `frmC.txtFirstName.Text = "Bob"`, which will update a control on FormC. If you want to send me your email address I can provide you with an example project that does what I'm talking about. – Bradley Uffner Dec 05 '11 at 19:52
  • Sure sir. My mail ID: sgskavya@gmail.com. Please send me the example project. Thanks & Regards – user993444 Dec 06 '11 at 05:25