Rich Text Box to Variable
I have incoming messages from a socket client going into a rich text box. Is there a way to find a part of a string and then extract x amount of characters out of that line into a variable?
Example:
I send a <T> command to the unit
I send a <V> command to the unit
the unit responds into the RTB
<TXXXX>
<VXXXX>
(XXXX could be any combination of numbers)
I need to get the TXXXX and put it in 1 variable and put the VXXXX into another variable.
Re: Rich Text Box to Variable
it'll be easier to intercept it before it gets in to the rtb
Re: Rich Text Box to Variable
here's an example using regex:
vb Code:
Dim testStr As String = "<T1234>" & Environment.NewLine & "<V5678>"
Dim rx As New Regex("(?<=\<T).+?(?=\>)")
MsgBox(String.Format("T{0}", rx.Match(testStr).Value))
rx = New Regex("(?<=\<V).+?(?=\>)")
MsgBox(String.Format("V{0}", rx.Match(testStr).Value))
don't forget to import regex:
vb Code:
Imports System.Text.RegularExpressions
Re: Rich Text Box to Variable
Quote:
Originally Posted by
.paul.
it'll be easier to intercept it before it gets in to the rtb
That would be so much easier, I do not like RTB. RegEx is already installed with VS2008 correct? I am new to VS2008.
Re: Rich Text Box to Variable
yes regex is installed. to use my code you need to import it as i recommended
Re: Rich Text Box to Variable
this is where you put imports statements. at the top line of your form or class:
vb Code:
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Re: Rich Text Box to Variable
vb Code:
Here is how my message are received, how do I intercept them?
Private Sub appendText1(ByRef incomingMessage1 As String)
rtbR1.Clear()
'Delegates.RichTextBoxes.appendText(Me, rtbDebug, incomingMessage1)
Delegates.RichTextBoxes.appendText(Me, rtbR1, incomingMessage1)
If frmMain.lbStations.SelectedIndex = 1 Then
Delegates.RichTextBoxes.appendText(frmMain, frmMain.rtbMain, incomingMessage1)
End If
End Sub
Re: Rich Text Box to Variable
it looks like incomingMessage1 is the text in 2 parts
Re: Rich Text Box to Variable
From what I understand from the code I manipulated, I have to use the delegates command to be able to see the message coming in and RTB is the only option I can see. I could be wrong and I hope I am... Here is the code I use to connect, you can see where I define it.
vb Code:
Try
AddHandler readerSock1.IncomingData, AddressOf appendText1
readerSock1.Connect(arrIP.Item(0), arrPort.Item(0))
If readerSock1.isConnected Then
rtbDebug.AppendText("Reader 1 Connected" & vbCrLf)
Else
rtbDebug.AppendText("Reader 1 NOT Connected" & vbCrLf)
End If
Catch ex As Exception
rtbDebug.AppendText(ex.Message)
End Try
The addressOf command I am not to familiar with. Maybe there is a better command?