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.
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.