0

im just wondering on how can i pass value of a variable to another form from a different form I have a form called frmSearch then I have another form called frmMain from frmSearch i have a varible A which is publicly declared and i wanted the value of A to frmMain i've tried the following

frmMain

dim B = frmSearch.A but everytime i checked the value of B it always returns a blank string also when i checked the value of frmSearch.A it also returns nothing even though it returns a value when i checked it in frmSearch

please help im really stuck thanks in advance

1
  • Show code, how you create instance frmSearch inside frmMain. Commented Jan 24, 2014 at 7:15

1 Answer 1

1

Accessing a field of a form shouldn't be a problem. Just make sure that at the time you are reading the field it is already assigned.

Public Class Form1
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim form = New Form2
        Debug.Assert(form.A Is Nothing)

        form.ShowDialog()

        Debug.WriteLine(form.A(0))
    End Sub
End Class



Public Class Form2
    Public A As String()

    Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        A = {"abc", "aaa"}
    End Sub
End Class
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.