Problem with display

johnadonaldson

Well-known member
Joined
Nov 9, 2005
Messages
48
Programming Experience
10+
I have a problem that hopefully someone can tell me what I am doing wrong or a better way to do this. I am sending commands to a device using RS232. When I get the return, it looks OK, but having a problem displaying the results.

First here is the RS232 return routine in the Main Form

PublicShared nResult AsInteger
Dim sBuf AsString

Private
Sub tmrRead_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrRead.Tick
Try
' As long as there is information, read one byte at a time and
' output it.
While (oCP.Read(1) <> -1)
'Write data to terminal screen
fOpTerm.DisplayMessage(Chr(oCP.InputStream(0)), False)
'Write data to buffer
sBuf += Chr(oCP.InputStream(0))
EndWhile
Catch exc As Exception
' An exception is raised when there is no information to read.
' Don't do anything here, just let the exception go.
EndTry
If Len(sBuf) > 0 Then
Me.TextBox3.Text = Microsoft.VisualBasic.Right(sBuf, 6)
Me.TextBox3.Text = Microsoft.VisualBasic.Left(Me.TextBox3.Text, 2)
nResult =
Me.TextBox3.Text
Else
sBuf = String.Empty
EndIf
EndSub


In a User Control I am displaying the result as


PrivateSub TextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Click
DoText1()
EndSub

PrivateSub DoText1()
Dim sMS1_ID AsString
sMS1_ID = "R 01 0074 000 01"
MainForm.SendRS232(sMS1_ID)
If MainForm.nTypeOut = 1 Then
If MainForm.nOnReg1 Then
If MainForm.nResult > 0 Then
Me.TextBox2.Text = Hex(MainForm.nResult.ToString)
Me.Label24.Visible = True
EndIf
EndIf
EndIf
EndSub

In the MainForm TextBox3 I can see the result, but when it displays in
the User Control TextBox2, it's not correct. It sometimes appears in
TextBox1.

Can someone tell me what I am doing wrong??
 
Back
Top