Question Multiple forms

Tiaan

Member
Joined
Mar 25, 2015
Messages
15
Programming Experience
1-3
I have my main form, with serialport1. All my baudrate and connect settings are on my form1. I connect and then hide form1. How do i use the serialport in form1 on my Form2? Im not sure where to start even so a nudge in the right direction would be great.

Im using vb.net

Thank you
 
You simply need to pass a reference to the SerialPort from the first form to the second. It's exactly the same as passing an Integer or a String. If you want more information, follow the Blog link in my signature below and check out my three-part post on Data Among Multiple Forms.
 
I cant seem to write back to form1 though. I get everything on form2 and works well, but i cant write from form2 to form1.
In Form1 i can only use Me.Close() i cant refer to Form1.Close(). Im fairly new to vb.net
 
I have my connect settings on Form1, after i connect, i hide Form1 with Me.Hide(). But now on form2 i need to go back to form1 so i can disconnect. I tried using Form1.Show() but does not give me permission to use form1.
 
I made a really terrible mistake. I must have changed the name of form1, or never named it. I got it right thank you for your help.
 
I thought i would ask here again and not start a new thread as it seems you know a lot about multiple forms.
Private Sub OnTimedEvent(ByVal state As Object)

If Not FrmForm1.isInSave Then
File.WriteAllLines("TmpRadial2.txt", LstRadial2.ToArray)
File.WriteAllLines("TmpTangential2.txt", LstTangential2.ToArray)
File.WriteAllLines("TmpVertical2.txt", LstVertical2.ToArray)
End If

End Sub
This is how i declared it at the top
Public FrmForm1 As Form1

If i use Form1.isInsave then it does not give me an error, but does not do what i need. When i use FrmForm1 it gives me this error error.jpg
 
As the error indicates you need to use an instance of the form of which calling it by the class name isn't an instance.
When you show the 2nd form you should pass a reference to the first form (Me) to it so you can access the instance of the first form on the second one.

For example, when you use Show/ShowDialog pass it 'Me':
SecondForm.Show(Me)
SecondForm.ShowDialog(Me)

Then on the second form:
DirectCast(Me.Owner, FrmForm1).isInSave
 
I thought i would ask here again and not start a new thread as it seems you know a lot about multiple forms.

For future reference, please keep each thread to a single topic and each topic to a single thread. If you have new questions that don't relate directly to an existing topic then please ask them in their own thread.
 
Back
Top