Problem pass data

johnadonaldson

Well-known member
Joined
Nov 9, 2005
Messages
48
Programming Experience
10+
I am trying to pass the same data to two different forms and textboxs. Both forms contain subroutines

Form1 - Main

Private Sub WriteMessage(ByVal message As String, ByVal linefeed As Boolean)
Me.TextBox2.Text += message
If linefeed Then
Me.TextBox2.Text += vbCrLf
End If
TextBox2.SelectionStart = TextBox2.Text.Length
End Sub

Form2 - Modless

Private Sub WriteMessage(ByVal message As String, ByVal linefeed As Boolean)
Me.TermRx.Text += message
If linefeed Then
Me.TermRx.Text += vbCrLf
End If
TermRx.SelectionStart = TermRx.Text.Length
End Sub

The calling routine is in Form1 as:

Form1

Private fOpterm as New Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
' Enable the timer.
' Write an user specified Command to the Port.
oCP.Write(Encoding.ASCII.GetBytes(Me.TextBox1.Text & Chr(13)))
WriteMessage(TextBox1.Text,
True)
fOpterm.WriteMessage(TextBox1.Text,
True)
Catch ex As Exception
' Warn the user.
MessageBox.Show("Unable to write to comm port")
Finally
TextBox1.Text = ""
TextBox1.Focus()
End Try
End Sub

Data is displayed in the textbox for Form1 but not in the TextBox for Form2.

Can someone tell me what I am doing wrong.
 
Hey John,

Not totally sure here, as I'm not sure why it wouldn't throw an error at design time, but if you make the sub WriteMessage in Form2 "Public" rather than "Private" I don't see any reason why this app shouldn't work.

Hope this helps.
 
Found the problem. In the routine that opens the window I had

Dim fOTrm as New Terminal

fOtrm.show()

and at the top of the program I had

Private fOTerm as New Terminal

took out the DIM in the routine that opens the window and relabeld it to
read

fOTerm.show()

Now it works. Thanks for the help
 
Back
Top