1

I have tried looking for a similar problem but I haven't found any for VB.

I have multiple forms, all of which with their own design and function. Form1 creates a StreamWriter file and will launch the other forms. Form2 and so on need to be able add to the same file, however I cannot access the file from the other forms.

I have tried declaring the file as Public in Form1, and also I have tried using:

Form1:

Dim newForm As New Form2(myFile)
newForm.show()

Form2:

Public Sub New(ByVal myFile As StreamWriter)
    Me.myFile = myFile
End Sub

but this will load Form2 without any of the controls I put on it in design mode.

1 Answers1

2

You are missing the InitializeComponent() method

Public Sub New(ByVal myFile As StreamWriter)

InitializeComponent()

Me.myFile = myFile

End Sub

For more info read Very Simple definition of InitializeComponent(); Method

Community
  • 1
  • 1
Hadi
  • 31,125
  • 9
  • 49
  • 111