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

Jeline Esase
  • 84
  • 1
  • 8

1 Answers1

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
milkyway
  • 55
  • 5